0 votes
in Jquery by

Using jQuery, how can I cancel/abort an Ajax request that I have not yet received the response from?

I've an AJAX request which will be made every x seconds. But the problem is before the AJAX request if the previous request is not completed I've to abort that request and make a new request.

1 Answer

0 votes
jQuery Ajax methods return an XMLHttpRequest (or the equivalent) object, so you can just use abort()

    var xhr;

    var fn = function(){
        if(xhr && xhr.readyState != 4){
        xhr = $.ajax({
            url: 'ajax/progress.ftl',
            success: function(data) {
                //do something

    var interval = setInterval(fn, 500);

Related questions

+2 votes
2 answers 7.1k views
+1 vote
1 answer 438 views
+1 vote
1 answer 2.3k views
+1 vote
1 answer 2.2k views