Home  >  Article  >  Web Front-end  >  A comprehensive understanding of jquery's ajax request_jquery

A comprehensive understanding of jquery's ajax request_jquery

WBOY
WBOYOriginal
2016-05-16 17:39:52997browse

jquery encapsulates some ajax request methods, which is 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() - Use HTTP POST request to load 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 such that Suitable for a URL query string or Ajax request
jQuery.getScript() - load a js file from the server and then execute it
jQuery.getJSON( )——Load JSON-encoded data from the server
jQuery.get()——Load data from the server Simply two points

1. .ajaxStart() and .ajaxStop()

Copy code The code is as follows:








Trigger






The class in the code is result The element 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

Finally

Copy code The code is as follows:

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

2. .ajaxSend(), .ajaxComplete(), .ajaxSuccess() and .ajaxError()
Copy code The code is as follows:








Trigger







上述代码中还是class为result的加载一个html文件。

执行顺序代码中已经标出

如果请求过程中出现什么错误,比如说文件不存在等,就会执行.ajaxError()中的方法而不是.ajaxSuccess()中的。

以前总是对ajax认识很乱,现在有个全面的认识,总结一下,希望共同学习,另外请求中的方式是HTTP GET还是HTTP POST也是值得研究的。

jquery中介绍ajax的地址ajax的使用

Statement:
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