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

Use of jQuery's AJAX functions

PHP中文网
Release: 2016-05-16 19:25:36
Original
1140 people have browsed it

What is AJAX?

AJAX = Asynchronous JavaScript and XML.

AJAX is a technology for creating fast and dynamic web pages.

AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server in the background. This means it is possible to update a portion of a web page without reloading the entire page.

AJAX and jQuery

jQuery provides a rich library of functions (methods) for AJAX development.

With jQuery AJAX, you can request TXT, HTML, XML or JSON from a remote server using both HTTP Get and HTTP Post.

Load function

$(selector).load(url,data,function(response,status,xhr)))
The simplest application is to load a file on a web page, for example txt,html
For example: $('#myDiv').load('/jquery/test1.txt'); is to load the words in the test1.txt file placed in the jquery folder into the class= of the web page in the "muDiv" node.

get() method

$(selector).get(url,data,success(response,status,xhr),dataType)
url is required. Specifies the URL to which the request will be sent.
data is optional. Specifies the data to be sent to the server with the request.
success(response,status,xhr)optional. Specifies a function to run when the request is successful.
response - contains the number of results from the request, status - contains the status of the request, xhr - contains the XMLHttpRequest object
dataType is optional. Specifies the data type of expected server response.
If written as ajax, it is:
$.ajax({
url: url,
data: data,
success:
success,
dataType: dataType
});

post() method

jQuery.post(url,data,success(data, textStatus, jqXHR),dataType)
Similarly: ajax means:
$.ajax({
type: 'POST',
url: url,
data: data,
success: success,
dataType:dataType
}); The

ajaxError()

ajaxError() method executes a function when an error occurs in an AJAX request. It is an Ajax event.

That is, when the AJAX request fails, use

$("div").ajaxError(function(){ alert("An error occurred!"); }); for example, a prompt will pop up when it fails. Box

ajaxSuccess() method

Similarly, the ajaxSuccess() method executes the function when the AJAX request is successful. It is an Ajax event

These are the most commonly used methods, and others are found by yourself.


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