jquery encapsulates some of the AJAX request methods that are practical.
For example. Ajaxcomplete ()-When the request completes. Ajaxerror ()--when the request fails. Ajaxsend ()--Append a function to the AJAX request when it is sent. Ajaxstart ()--When the request starts,. ajaxstop ()--at the end of the request. Ajaxsuccess ()--when the request succeeds. Load ()-loads the data from the server and replaces the returned HTML with the selected element Jquery.post ()-Loads the server-side data using an HTTP POST request. Serialize ( --Encodes a FORM element set into a string for submission. Serializearray ()--encodes a FORM element set into a key-value array of Jquery.param ()--Creates a serialized array or object, Make it applicable to a URL query string or AJAX request Jquery.getscript ()-Load a JS file from the server and execute it jquery.getjson ()-Load the JSON-encoded data from the server Jquery.get ()- Loading data from the server simply say 2.1,. Ajaxstart () and. Ajaxstop ()
Copy Code code as follows:
<! DOCTYPE html>
<script type= "Text/javascript" src= "Test/jquery-1.7.2.min.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ('. Log1 '). Ajaxstart (function () {
$ (this). Text (' triggered Ajaxstart handler. ');
});
$ ('. log2 '). Ajaxstop (function () {
$ (this). Text (' triggered ajaxstop handler. ');
});
$ ('. Trigger '). Click (function () {
$ ('. Result '). Load (' xixi.html ');
});
});
</script>
<body>
<div class= "Trigger" >Trigger</div>
<div class= "Result" ></div>
<div class= "Log1" ></div>
<div class= "log2" ></div>
</body>
The element in the code class for result is load a xixi.html, the content of this file is random, as long as the existence of this file on the line. The order of the JS execution method is first
Copy Code code as follows:
$ (this). Text (' triggered Ajaxstart handler. ');
And then
Load the contents of the late xixi.html into the element of result in class
At last
Copy Code code as follows:
$ (this). Text (' triggered ajaxstop handler. ');
Two
Copy Code code as follows:
. Ajaxsend (),. Ajaxcomplete (),. ajaxsuccess () and. Ajaxerror ()
[HTML]
Copy Code code as follows:
<! DOCTYPE html>
<script type= "Text/javascript" src= "Test/jquery-1.7.2.min.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ('. Log1 '). Ajaxstart (function () {
$ (this). Text (' triggered Ajaxstart handler. '); /"1"
});
$ ('. log2 '). Ajaxstop (function () {
$ (this). Text (' triggered Ajaxstart handler. '); /"5"
});
$ ('. Result '). Ajaxsend (function () {
$ (this). Text (' triggered ajaxsend handler. '); /"2"
});
$ ('. Result '). Ajaxcomplete (function () {
$ (this). Text (' triggered Ajaxcomplete handler. '); /"4"
});
$ ('. Result '). Ajaxsuccess (function () {
$ (this). Text (' triggered ajaxsuccess handler. '); /"3"
});
$ (". Result"). Ajaxerror (function () {
$ (this). Text ("triggered Ajaxerror handler.");
});
$ ('. Trigger '). Click (function () {
$ ('. Result '). Load (' xixi.html ');
});
});
</script>
<body>
<div class= "Trigger" >Trigger</div>
<div class= "Result" ></div>
<div class= "Log1" ></div>
<div class= "log2" ></div>
</body>
The code above or class is loading an HTML file for result.
The execution sequence code is already marked
If there are any errors in the request, such as if the file does not exist, the method in the. Ajaxerror () is executed instead of. Ajaxsuccess ().
Before always on the Ajax understanding is very messy, now have a comprehensive understanding, summed up, hope to study together, the other request in the way is HTTP GET or HTTP POST is also worth studying.
Ajax addresses the use of Ajax in jquery
The greater the responsibility, the more andy_ the power.