Jquery $. ajax usage sharing. If you are using jquery, refer
The Code is as follows:
$. Ajax ({
Type: "GET ",
Url: "Services/EFService. svc/Members ",
Data :"{}",
ContentType: "application/json; charset = UTF-8 ",
DataType: "json ",
Success: function (data ){
// Play with returned data in JSON format
},
Error: function (msg ){
Alert (msg );
}
});
A global event is triggered by every Ajax request. It broadcasts all the elements in the DOM. The script loaded in the preceding getScript () example is a global Ajax event. Global events can be defined as follows:
The Code is as follows:
$ ("# Loading"). ajaxStart (function (){
$ (This). show ();
});
We can disable global events in a specific request, as long as the global option is set:
The Code is as follows:
$. Ajax ({
Url: "test.html ",
Global: false, // disable global Ajax events .//...});
The following is a complete list of Ajax events officially provided by jQuery:
• AjaxStart (Global Event)
This event is broadcast if an Ajax request is started and no other Ajax requests are currently running.
• BeforeSend (Local Event)
This event, which is triggered before an Ajax request is started, allows you to modify the XMLHttpRequest object (setting additional headers, if need be .)
• AjaxSend (Global Event)
This global event is also triggered before the request is run.
• Success (Local Event)
This event is only called if the request was successful (no errors from the server, no errors with the data ).
• AjaxSuccess (Global Event)
This event is also only called if the request was successful.
• Error (Local Event)
This event is only called if an error occurred with the request (you can never have both an error and a success callback with a request ).
• AjaxError (Global Event)
This global event behaves the same as the local error event.
• Complete (Local Event)
This event is called regardless of if the request was successful, or not. You will always receive a complete callback, even for synchronous requests.
• AjaxComplete (Global Event)
This event behaves the same as the complete event and will be triggered every time an Ajax request finishes.
• AjaxStop (Global Event)
This global event is triggered if there are no more Ajax requests being processed.
JQuery. ajaxSetup (options): sets the global AJAX default options.
Set the default address of an AJAX request to "/xmlhttp/". Do not trigger a global AJAX event. Use POST instead of the default GET method. No option parameters are set for subsequent AJAX requests.
JQuery code:
The Code is as follows:
$. AjaxSetup ({
Url: "/xmlhttp /",
Global: false,
Type: "POST"
});
$. Ajax ({data: myData });
If it is specified as html, any embedded JavaScript will be executed before HTML is returned as a string. Similarly, if the script type is specified, the server will first generate JavaScript and then return the script as a text data.
JSON data is a structured data that can be easily parsed using JavaScript. If the obtained data file is stored on a remote server (the domain name is different, that is, cross-Origin data retrieval), The jsonp type is required. If this type is used, a query string parameter callback =? will be created? This parameter is added after the request URL. The server should add the callback function name before the JSON data to complete a valid JSONP request. If you want to specify the callback function parameter name to replace the default callback, you can set the jsonp parameter of $. ajax.