Use of jQuery AJAX Functions

Source: Internet
Author: User
Use of jQuery AJAX Functions What Is AJAX?

AJAX = Asynchronous JavaScript and XML.

AJAX is a technology for creating fast dynamic web pages.

AJAX allows asynchronous updates on webpages by exchanging a small amount of data with the server in the background. This means that it is possible to update part of the webpage without reloading the whole page.

AJAX and jQuery

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

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

Load Function

$ (Selector). load (url, data, function (response, status, xhr )))
The simplest application is to load a webpage file, such as txt and html.
For example, $ ('# myDiv'). load ('/jquery/test1.txt'contains characters that are stored in the test1.txt file in the jqueryfolder and loaded into the class = "muDiv" node of the webpage.

Get () method

$ (Selector). get (url, data, success (response, status, xhr), dataType)
The url is required. Specifies the URL of the request.
Data is optional. Specifies the data sent to the server together with the request.
Success (response, status, xhr) is optional. Specifies the function that runs when the request is successful.
Response-contains the number of results from the request, status-contains the Request status, and xhr-contains the XMLHttpRequest object
DataType is optional. Specifies the expected server response data type.
If it is 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 indicates:
$. Ajax ({
Type: 'post ',
Url: url,
Data: data,
Success: success,
DataType: dataType
});

AjaxError ()

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

That is, when an AJAX request fails

$ ("P"). ajaxError (function () {alert ("An error occurred! ") ;}); For example, a prompt box is displayed when a failure occurs.

AjaxSuccess () method

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

This is the most common method, and other methods are available on your own.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.