jquery encapsulates some of the AJAX request methods that are practical.
Like what
. Ajaxcomplete ()--When the request completes
. Ajaxerror ()--When a request fails
. Ajaxsend ()--Append a function to execute when the AJAX request is sent
. Ajaxstart ()--at the start of the request,
. Ajaxstop ()--at the end of the request
. Ajaxsuccess ()--When the request succeeds
. Load ()-load data from the server and replace the returned HTML with the selected element
Jquery.post ()--Loading server-side data with HTTP POST requests
. Serialize ()--encodes a FORM element set into a string to submit
. Serializearray ()--encodes a FORM element set into an array of key values
Jquery.param ()--Creates a serialized array or object that applies to a URL query string or AJAX request
Jquery.getscript ()-Load a JS file from the server and execute it
Jquery.getjson ()--load JSON-encoded data from the server side
Jquery.get ()--loading data from the server it's a simple two point.
I. 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 in which JS executes the 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. ');
Ii.. Ajaxsend (),. Ajaxcomplete (),. ajaxsuccess () and. Ajaxerror ()
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