开发者

AJAX postback in jQuery

开发者 https://www.devze.com 2022-12-09 16:24 出处:网络
I\'m having an AJAX request on the page. Is there a way to find when a AJAX-call is triggered on the page.

I'm having an AJAX request on the page.

Is there a way to find when a AJAX-call is triggered on the page. In jQuery or javascript to find or initiate a function with AJAX req开发者_开发问答uest is called on a page.


See ajaxStart and ajax events. Example:

 $("#loading").bind("ajaxSend", function(){
   $(this).show();
 }).bind("ajaxComplete", function(){
   $(this).hide();
 });


You can bind a function to a JQuery object to be completed when any AJAX call completes.

$('#status').ajaxComplete(function(event, request, settings) {
    // Do stuff here...
});

See the documentation.

If you want to set a complete function for a single AJAX call, use the low-level $.ajax() function and setting a function for the complete attribute.

$.ajax({
    // ...
    complete: function(request, settings) {
         // Do stuff here...
    },
    // ...
});

Note: the documentation seems to contradict itself in specifying the number of arguments to the complete() function. It may take some fiddling.

0

精彩评论

暂无评论...
验证码 换一张
取 消