Directory (updated articles will be connected, and an article will be updated every two to three days starting from March 13, July 25 ):
ASP. NET + jquery. Ajax details 1-opening section (published on February 25)
ASP. NET + jquery. Ajax details 2-$. Load (published on 2012.07.26)
ASP. NET + jquery. Ajax details 3-$. Get and $. Post (published on February 30)
ASP. NET + jquery. Ajax details 4-$. getjson (published on February 31)
ASP. NET + jquery. Ajax details 5-$. getscript (2012.08.04)
ASP. NET + jquery. Ajax details 6-$. ajaxsetup (2012.08.06)
ASP. NET + jquery. Ajax details 7-Global Ajax events (published on 2012.08.09)
ASP. NET + jquery. Ajax details 8-core $. Ajax (published on February 12)
ASP. NET + jquery. Ajax details 9-serialize and serializearray (February 15)
ASP. NET + jquery. Ajax detailed description: 10-json and XML + are written at the end of the article (published on February 20 !)
Global Ajax events are a series of events that accompany Ajax requests.
There are mainly the following events:
Execution function when ajaxcomplete (callback) Ajax request is complete
Ajaxerror (callback) the execution function when an error occurs in an Ajax request
Ajaxsend (callback) Ajax request execution function before sending
Ajaxstart (callback) the function is executed when the Ajax request starts.
Ajaxstop (callback) the function is executed when the Ajax request ends.
Execute the function when the ajaxsuccess (callback) Ajax request is successful.
When learning $. ajaxsetup, we know that the global attribute of the default options is true, which indicates that these global events will be triggered when an Ajax request is sent.
You can use $. ajaxsetup to set the global attribute of the default options to false to cancel triggering a global Ajax event.
The callback functions of these events (except ajaxstart and ajaxstop) contain three parameters.
Event-contains the event object
Xhr-contains XMLHTTPRequest object
Options-contains the options used in Ajax requests
We use an instance to describe when these events occur. In this way, you can understand it more intuitively.
Instance-Client
<% @ Page Language = "C #" autoeventwireup = "true" codebehind = "jqueryajaxglobalevent. aspx. cs" inherits = "jqueryajaxtest. jqueryajaxglobalevent" %> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
Server --
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. web. ui; using system. web. UI. webcontrols; namespace jqueryajaxtest. data {public partial class getmethodinfo: system. web. UI. page {protected void page_load (Object sender, eventargs e) {string Param = ""; // obtain the parameter if (! String. isnullorempty (httpcontext. current. request ["Param"]) {Param = httpcontext. current. request ["Param"];} // clear the Buffer Response. clear (); // write the string to the response output stream response. write ("HTTP Request Method:" + request. httpmethod. toupper () + "; the passed parameter is:" + PARAM); // the client that sends all the current buffered outputs and stops this page from executing response. end ();}}}
Note the differences between ajaxsuccess and ajaxcomplete:
Ajaxsuccess: When this event is triggered when the request is successful, the callback function will get the parameter. The attribute status of a parameter is = 200.
Ajaxcomplete: this event is triggered when the request is complete, and the callback function will get this attribute status = 404, 403, 302 .... Unlike ajaxsuccess (), functions defined by the ajaxcomplete () method run when the request is complete, even if the request is not successful.
We often write this in native Ajax,
XMLHTTP. onreadystatechange = function ()
{
If (XMLHTTP. readystate = 4 & XMLHTTP. Status = 200)
{
Document. getelementbyid ("mydiv"). innerhtml = XMLHTTP. responsetext;
}
}
When readystate is 4 and the status is 200, the response is ready. When the status is 200, that is, the time when our ajaxsuccess event is triggered.
Ah, I have written 7 articles in this series, and there are 3 more articles. Continue!