jquery多个ajax请求 - 导致php对象出现问题

时间:2012-06-15 14:16:29

标签: php jquery ajax object

我正在尝试一次处理和更新1000个项目的查询。 我把设置缓存设置为false,甚至尝试使用setTimeout在请求之间暂停。 每个请求应该花费5-6秒,然后该过程将永远不会超时,但是在4-5个请求之后它将达到服务器执行限制。

问题是我需要在更新查询中使用PHP对象。 每个请求似乎都需要更长的时间,因此似乎对象在PHP中循环

无论如何都要阻止这种情况发生?

这是javascript代码

function processIndex() {
    $.ajax({
        url: responder,
        dataType: "json",
        data: data,
        cache: false,
        async: false,
        error: function(XMLHttpRequest, textStatus, errorThrown){
        //  alert('status:' + XMLHttpRequest.status + ', status text: ' + XMLHttpRequest.statusText + ' LIMIT ' + limitFrom + ', ' + limitTo);
            limitFrom = limitTo;
            limitTo  += 1000;
            processIndex('indexPrices');
        },
        success: function(data) {
                    limitFrom = limitTo;
                    limitTo  += 1000;
                    setTimeout(function() {
                        processIndex();
                    }, 1000);
                }
            });
        }
    });
}

1 个答案:

答案 0 :(得分:0)

你可以使用 http://www.protofunc.com/scripts/jquery/ajaxManager/

OR

https://gist.github.com/2470554

排队ajax请求。

另一种方法是发送少量记录(一次说50条记录)并在服务器端代码中循环它们。

您可以将这两种解决方案结合起来以获得最佳效果