且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取最新的AJAX请求,并放弃其他

更新时间:2023-02-20 18:06:44

This说明如何使用jQuery做一个Ajax调用,以及如何终止它。所有你需要做的就是创建一个存储每个请求的数组。然后,您可以同时加入了新的取消previous请求。

This explains how to use jQuery to do an ajax call and how to abort it. All you need to do is create an array that stores each request. You could then cancel the previous request while adding the new one.

ajaxRequests = new Array();

queueRequest = function(whatever, you, want) {
    if(ajaxRequests[ajaxRequests.length - 1]) {
        ajaxRequests[ajaxRequests.length - 1].abort();
    }

    ajaxRequests[ajaxRequests.length] = //Insert New jQuery AJAX call here.
}