How to cancel/abort jQuery AJAX request?

I’ve an AJAX request which will be made every 5 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.

My code is something like this, how to resolve this issue?

$(document).ready(
    var fn = function(){
        $.ajax({
            url: 'ajax/progress.ftl',
            success: function(data) {
                //do something
            }
        });
    };

    var interval = setInterval(fn, 500);
);

8 Answers
8

Leave a Comment