FR.ajax

  • Last update:January 26, 2022
  • 注:以下为10.0版本文档参考

    I. FR.ajax

    We all know that JS is the front-end code, which is directly executed by the browser and does not interact with the server.

    With Ajax, users can use JavaScript's XMLHttpRequest object to communicate directly with the server. And exchange data with the web server without reloading the page. The so-called asynchronous request .

    II. Calling syntax

    Able to pass

    FR.ajax(options)

    Call it anywhere you can use JavaScript.

    1. Parameters

      Parameter
     Type
     Instruction
       options  Object  Required, Ajax parameter

    options are provided in JSON format with the following properties:

     AttributesType  
    Instruction  
      url  String  Required, the address to send the request to
      type  String  The request method is POST/GET, the default is GET
      timeout  Number  Set the request timeout in milliseconds, this setting will override the global setting.
      success  Function  Callback function after successful request
    success: function(data, textStatus){  
     // data is returned by the server and processed according to the dataType parameter. textStatus is the status value success
    }
    Example: FR.ajax({ url: "/webapps/webroot/a.html", success: function(data, textStatus){ alert(this.url); } });
      error  Function  Call this function when the request fails
    error: function(XMLHttpRequest, textStatus, errorThrown){  //The parameters are the XMLHttpRequest object, the error message, and the captured exception object. Usually only one of textStatus and errorThrown will contain information  } Example: FR.ajax({ url: "some.jsp", error: function(XMLHttpRequest, textStatus, errorThrown){ alert(this.url); } }); 



     dataType  String  The expected data type returned by the server. If not specified, it will be automatically judged intelligently based on the MIME information of the HTTP packet. Available values are:
    "xml": returns an XML document
    "html": returns plain text HTML information; the included script tag is executed when inserted into the dom.
    "script": Returns plain text JavaScript code.
    "json": Returns JSON data.
    "text": Returns a plain text string.
    "jsonp" : use jsonp across domains
      data Object 
      Data sent to the server. GET requests are automatically converted to request string format and appended to the URL.
    The value must be in Key/Value format, which can be a string such as "p1=pavalue&p2=p2value", or an object such as {p1:p1value,p2:p2value}
     complete Function  The callback function after the request is completed (called after the request succeeds or fails)
     complete: function(XMLHttpRequest, textStatus){  
    //The parameters are the XMLHttpRequest object and a string describing whether the request is successful or not
     }
    Example: FR.ajax({ url: "some.jsp", complete: function(XMLHttpRequest, textStatus){ alert(this.url); } });
    The option value in the Ajax request can be called through this.xxx in the function.
      async  Boolean  The default is true, all requests are asynchronous requests. Set this option to false if you need to send synchronous requests.Note: A synchronous request will lock the browser, and the user must wait for the request to complete before performing other operations.

    III. Example

     Example: For details, please see  Ajax Asynchronous Cross-domain SSO

    注:以下为11.0版本文档参考

    ajax is the encapsulated jQuery.ajax() function, which makes an ajax request to a specific web page in the report, and the data parameter is encoded in Chinese, Japanese, and Korean.

    Parameter Description

    options is a jax parameter, described in the following table:

    ParameterTypeInstruction
    optionsObjectRequired, ajax parameter

    [options] is provided in json format, the properties are shown in the following table:

    AttributesTypeInstruction
    urlStringRequired, the address to send the request to
    dataObjectData sent to the server. GET requests are automatically converted to request string format and appended to the URL.

    value must be Key/Value format, which can be a string such as p1=pavalue&p2=p2value, or an object such as {p1:p1value,p2:p2value}

    typeStringThe request method is POST/GET, the default is GET
    dataTypeString

    The expected data type returned by the server. If not specified, it will be automatically judged intelligently according to the MIME information of the HTTP packet. Available values are:

    "xml": Returns an XML document
    "html": Returns plain-text HTML information; the included script tags are executed when inserted into the dom.
    "script": Returns plain text JavaScript code.
    "json": Returns JSON data.
    "text": Returns a plain text string.
    "jsonp" : use jsonp across domains

    successFunction

    The callback function after the request is successful, the format is as follows:

    success: function(data, textStatus){  
    // data is returned by the server and processed according
    to the dataType parameter.
    //textStatus is the status value success
    }

    The following example:

    FR.ajax({
    url: "/webapps/webroot/a.html",
    success: function(data, textStatus{
    alert(this.url);
    }
    });
    errorFunction

    This function is called when the request fails, in the format:

    error: function(XMLHttpRequest, textStatus, errorThrown)
    //The parameters are the XMLHttpRequest object, the error message,
    and the captured exception object.// Usually only one of textStatus and errorThrown will
    contain information
     }

    The following example:

    FR.ajax({
    url: "some.jsp",
    error: function(XMLHttpRequest, textStatus, errorThrown{
    alert(this.url);
    }
    });
    completeFunctionThe callback function after the request is completed (called after the request succeeds or fails), the option value in the ajax request can be called through this.xxx in the function.
    complete: function(XMLHttpRequest, textStatus){  
    //The parameters are the XMLHttpRequest object and
    a string describing whether the successful request was successful or not.
     }

    The following example:

    FR.ajax({
    url: "some.jsp",
    complete: function(XMLHttpRequest, textStatus{
    alert(this.url);
    }
    });
    timeoutNumberSet the request timeout in milliseconds, this setting will override the global setting.
    async Boolean

    The default is true, all requests are asynchronous requests. Set this option to false if you need to send synchronous requests.

    Note: A synchronous request will lock the browser, and the user must wait for the request to complete before performing other operations. 

    Example

    Send an ajax request in the cell hyperlink JavaScript script of cpt, and handle different situations in different callback functions:

    var username = "1";
    var password = "1";
    FR.ajax({   
       url:"http://env.finedevelop.com:59204/Test
    /ReportServer?op=fs_load&cmd=sso"
    ,
       data:{
            fr_username:username,
            fr_password:password
            },
       dataType:"jsonp",//Using jsonp across domains  
       timeout:5000,//Timeout time (unit: milliseconds)
       //success:function(data) { //The data parameter depends on the return value                                        
            //FR.Msg.alert("success",data.status);
       //},   
       //error:function(errorThrown){   
            //FR.Msg.alert("error",errorThrown);
       //},
       complete: function(res,textStatus)
            FR.Msg.alert("complete",textStatus); 
       }  
    })

    Attachment List


    Theme: Secondary Development
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy