Home > Web Front-end > JS Tutorial > body text

In-depth analysis of jquery ajax request examples_jquery

WBOY
Release: 2016-05-16 17:47:46
Original
1265 people have browsed it

jquery encapsulates some ajax request methods, which are very practical.
For example, .ajaxComplete() - when the request is completed. ajaxError() - when the request fails. ajaxSend() - attach a function to execute when the Ajax request is sent. ajaxStart() - when the request starts, .ajaxStop ()——When the request ends.ajaxSuccess()——When the request is successful.load()——Load data from the server and replace the returned HTML into the selected element jQuery.post()——Load using HTTP POST request Server-side data.serialize() - Encode the set of form elements into a string for submission. serializeArray() - Encode the set of form elements into an array of key-value pairs jQuery.param() - Create a serialized array or object, making it applicable to a URL query string or Ajax request jQuery.getScript() - loads a js file from the server and then executes it jQuery.getJSON() - loads JSON-encoded data from the server jQuery .get()——Loading data from the server is a simple matter of two points: 1. .ajaxStart() and .ajaxStop()

Copy code The code is as follows:







< ;body>
Trigger







The element whose class is result in the code loads a xixi.html. The content in this file is arbitrary, as long as this file exists. The order of js execution methods is first
Copy the code The code is as follows:

$(this). text('Triggered ajaxStart handler.');

Then
load the content in xixi.html into the element with class result
and finally
Copy code The code is as follows:

$(this).text('Triggered ajaxStop handler.');

2.
Copy code The code is as follows:

.ajaxSend(),. ajaxComplete(), .ajaxSuccess() and .ajaxError()

[html]
Copy code The code is as follows:








Trigger







In the above code, an html file is loaded with the class of result.
The execution sequence code has been marked
If there is any error during the request process, such as the file does not exist, etc., the method in .ajaxError() will be executed instead of .ajaxSuccess().
I always had a confusing understanding of ajax before, but now I have a comprehensive understanding. To summarize, I hope to learn together. In addition, whether the request method is HTTP GET or HTTP POST is also worth studying.
Introducing the use of ajax address in jquery
Andy_With greater ability comes greater responsibility
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template