开发者

.ajaxComplete prevent any callbacks calls. is it possible?

i have a backend written with php and a frontend on jQuery.. what i want to do:

  1. page contains several links with AJAX calls (each one has it's own sucess/error callbacks)
  2. php backend may return a reply something like this: {"must_relogin":true}
  3. i have to bind to some kind global AJAX event in jQuery to catch this response 开发者_如何学Goand do perform some my logic and to prevent any other callbacks

is it possible?

Thank you for help.

update

jQuery(document).ajaxComplete(function(a, b, c){ 
 console.log(a, b, c);
 b.abort();
 return false; });


Have you tried using event.stopImmediatePropagation()? It states "Prevents other event handlers from being called". From looking at the jQuery source we see this

if ( fireGlobals ) {
    globalEventContext.trigger( "ajaxComplete", [ jqXHR, s] );
    // Handle the global AJAX counter
    if ( !( --jQuery.active ) ) {
        jQuery.event.trigger( "ajaxStop" );
    }
}

Here is a working example of it potentially solving your problem, http://jsfiddle.net/Akkuma/95zfj/

The caveat is that it appears to not work if the ajaxCompletes are not all bound to the same element.


im not sure about your scenario but here is a SO link

Abort Ajax requests using jQuery

that explains aborting the ajax calls using .abort but if a call is already made to the server then .abort cannot close an existing connection to the server, all the success call backs of the ajax calls that has been already made will be executed anyway...

HTH


If I understand the question correctly, it is not possible to prevent the callback calls based on the response string. The problem is that the ajax global event handlers like ajaxSuccess and ajaxComplete are called after the callbacks have been executed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜