注:以下为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
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:
Attributes | Type | 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:
Parameter | Type | Instruction |
---|---|---|
options | Object | Required, ajax parameter |
[options] is provided in json format, the properties are shown in the following table:
Attributes | Type | Instruction |
---|---|---|
url | String | Required, the address to send the request to |
data | Object | Data 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} |
type | String | The request method is POST/GET, the default is GET |
dataType | String | 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 |
success | Function | The callback function after the request is successful, the format is as follows:
The following example:
|
error | Function | This function is called when the request fails, in the format:
The following example:
|
complete | Function | The 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.
The following example:
|
timeout | Number | Set 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);
}
})