Ajax global event Reference and individual events (global/local) execution order

Source: Internet
Author: User

This article focuses on the global event reference method for Ajax and the sequence of execution of each event, so let's read this article together.

All global events for the Ajax method of jquery:

Ajaxstart:ajax before the request begins

Ajaxsend:ajax when requested

Ajaxsuccess:ajax after getting the data

Ajaxcomplete:ajax when the request is complete

Ajaxerror:ajax after an error has occurred on the request

Ajaxstop:ajax after a request is stopped

The use of global events for AJAX methods

When you use jquery's ajax approach, both $.ajax (), $.get (), $.load (), $.getjson (), and so on, will trigger global events by default, but they are usually not bound to global events, but these global events are actually very useful.

Ajax global events, there is a typical application: your page has multiple or even a number of Ajax requests, but these AJAX requests have the same message mechanism. A prompt is displayed before the AJAX request begins, prompting "reading data", and the Prompt box displays "Data acquisition success" when the Ajax request succeeds, and hides the prompt after the AJAX request ends. The practice of not using global events is to add the $.ajax () plus the beforesend, success, and complete callback functions to the callback function with the Processing hints box. The practice of using global events is:

$ (document). Ajaxstart (OnStart).   ajaxcomplete (OnComplete)   . ajaxsuccess (onsuccess); function OnStart (event ) {//.....} function OnComplete (event, XHR, Settings) {//...} function Onsuccess (event, XHR, Settings) {//...}

Each event in jquery is executed in the following order

1.ajaxStart (Global event)

2.beforeSend (Local event)

3.ajaxSend (Global event)

4.success (Local event)

5.ajaxSuccess (Global event)

6.error (Local event)

7.ajaxError (Global event)

8.complete (Local event)

9.ajaxComplete (Global event)

10.ajaxStop (Global event)

Example

<! DOCTYPE html>
Related Article

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.