0

我有一个繁重的应用程序,其中所有内容都在 ajax 中。

现在有时在页面加载时有 10+ ajax 请求,其中一些随机失败,原因不明。

无论如何都知道为什么这些请求失败了?

我可以在 error: {} case 中捕获错误,如果发生故障,我应该再次调用 Ajax 函数还是它不是一个好主意(避免循环)?

这是我用来处理所有请求的 Ajax 函数:

function ajax(aurl,dataType,requestData,successListener,compelteListener,errorListener,async) {

var $xhr=null;
async = typeof async !== 'undefined' ? async : true;

if($.ajax) {
    $xhr=$.ajax({
        type: 'post',
        url : aurl,
        async : async,
        dataType : dataType,
        data:requestData,
        success: function(response){
            checkAjaxResponse(null,response,successListener,errorListener);
        },
        complete:compelteListener,
        error:function(response){
            checkAjaxResponse(null,response,errorListener);
        }
    });
}else {
    alert("jquery not found ..");
}
return $xhr;

}

更新 1:

如果我在错误内做一个 console.log 响应,我会得到以下信息:

  {"readyState":0,"responseText":"","status":0,"statusText":"error"}

更新 2:

查看 apache 日志,我看到了很多:

[notice] Parent: child process exited with status 255 -- Restarting.

我还将我的 ajax 请求修改为:

error:function(response){
 ajax(aurl,dataType,requestData,successListener,compelteListener,errorListener,async); 
}

但是如果 Ajax 总是失败,那可能会导致系统崩溃......

更新#3

我认为这更像是一个 WAMP 问题,因为我在生产中没有这些错误。

无论如何感谢大家的努力!

4

1 回答 1

0

问题与 Windows 上的 Apache 有关,原因不明,服务器随机崩溃。

我在 httpd 上找到了一些与堆栈相关的信息(1mb windows 默认 vs 8mb default on linux)

我们的产品是 linux 和 dev on windows 。

将函数修改为以下内容:

error:function(response){
                counter++;
                checkAjaxResponse(null,response,errorListener);
                if(counter > 5) {
                    jAlert(get_label('technical_error') + '<br><br>' + get_label('function_called')+ aurl,get_label('attention_loading')); 
                    setLoading(false);  
                } else {
                   return ajax(aurl,dataType,requestData,successListener,compelteListener,errorListener,async,counter);
                }
            }
于 2013-02-28T17:35:15.673 回答