当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Get all pending AJAX requests

问题描述:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: