How I can check all pending AJAX requests and skip all pending requests except last? For example, I have 3 payment methods and when I click rapidly 3-5 times I see 1 pending request and 3-5 waiting requests. So I need skip all of them except the last one.
Use this type of pattern
// Is an ajax request pending?
var isPending = false;
function doAjax(){
// If a request is pending, don't make another one
if(isPending) return;
// Set pending flag to true
isPending = true;
$.ajax({
// parameters and stuff
}).done(function(){
// reset the pending flag
isPending = false;
});
}
You can cancel the ajax calls by using timeout for each call http://geekswithblogs.net/lorint/archive/2006/03/07/71625.aspx