开发者

Jquery way to handle all ajax success events in one place

I have a scenario where i need to handle all jquery success events in common place. because i want some delegate to be called after all the ajax success events. I know we can use $.ajaxComplete or $.ajaxSucess for that. But the problem is all my ajax calls have their own success handlers, so eventually $.ajaxSucess will be overwritten .

And i know i can write a common method which i can put in all ajax suc开发者_运维技巧cess handlers. but i dont want to do that, i want to know a cleaner way.

is there a method handler already in jquery for that, or whats the best way to do it?


The $.ajaxSuccess method should work fine as seen in this live demo and it doesn't conflict with existing ajax success handlers. It is executed after each of them:

$('#msg').ajaxSuccess(function(result) {
    alert('ajax succeeded');    
});


$.when($.ajax("/page1.php"), $.ajax("/page2.php"))
  .then(mySuccessFunc, myFailureFunc);


try in this way-

 $.when(// your all ajax call)
   .then(//delegate handler after ajax succes)


$.ajaxSuccess is not overwritten by the local success handler, it is executed after the local one.


Does :

$.ajaxStop(...)

Fixes your problem ?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜