Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop jquery ajax request in ajaxStart

Tags:

jquery

ajax

Is it possible to stop the current ajax request from within the jquery global event ajaxStart?

like image 432
Joel Cunningham Avatar asked Aug 03 '12 01:08

Joel Cunningham


2 Answers

.ajaxStart doesn't have access to the xhr object. .ajaxSend does, however. You can stop it there. I don't know why you would want to do this, but remember that this is a global ajax event -- so this effectively stops all ajax requests(or at least those that don't have the global:false flag).

$('some-object').ajaxSend(function(e, xhr) {
    xhr.abort();
});
like image 177
nbrooks Avatar answered Nov 13 '22 19:11

nbrooks


FYI there's a third argument also which is the Ajax Options object used to create the request in case that is of help...

                                             |
                                             |
                                            \| /
                                             \/
$('some-object').ajaxSend(function(e, xhr, options) {
    xhr.abort();
});
like image 36
RoryH Avatar answered Nov 13 '22 19:11

RoryH