jquery Ajax Ajaxsuccess Examples and detailed instructions

Source: Internet
Author: User

. Ajaxsuccess (Handler (event, XMLHttpRequest, Ajaxoptions))
Returns

jquery Description:

Ajaxsuccess (Handler (event, XMLHttpRequest, Ajaxoptions))

Handler (event, XMLHttpRequest, ajaxoptions) The function to be invoked.
Whenever an AJAX request completes successfully, triggers the ajaxsuccess jquery event. Any and all have been used. The Ajaxsuccess () method registers a handler that is executed at this time.

To comply with this approach, we can build a basic AJAX load requirement:

<div class= "Trigger" >trigger</div>
<div class= "Result" ></div>
<div class= "Log" ></div>

We can put any element in our event handler:

$ ('. log '). Ajaxsuccess (function () {
$ (this). Text (' triggered ajaxsuccess handler. ');
});

Now, we can use any one of the Ajax requests for jquery

$ ('. Trigger '). Click (function () {
$ ('. Result '). Load (' ajax/test.html ');
});

The user clicks the button and the AJAX request completes successfully, the log displays the message.

Note:. Since Ajaxsuccess () is implemented as an instance method of a jquery object, we can use the This keyword, because what we're doing here refers to the element that is selected in the callback function.

When all ajaxsuccess handlers are invoked, no matter what AJAX requests are completed. If you must distinguish between the requirements, we can use the parameters passed to the handler. Every time a ajaxsuccess handler executes, it is through the event object, the XMLHttpRequest object, and the set object are the requirements used in the creation. For example, we can limit the processing-specific URLs that handle only our callback events:


$ ('. log '). Ajaxsuccess (function (E, XHR, settings) {
if (Settings.url = = ' ajax/test.html ') {
$ (this). Text (' triggered ajaxsuccess handler. ');
}
});


For example:
Displays a message when an AJAX request completes successfully.


$ ("#msg"). Ajaxsuccess (function (evt, request, settings) {
$ (this). Append ("<li>successful request!</li>");
});

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.