【问题标题】:Failed http requesthttp请求失败
【发布时间】:2013-02-28 12:38:36
【问题描述】:

我有一个繁重的应用程序,所有内容都在 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 问题,因为我在生产中没有这些错误。

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

【问题讨论】:

  • 如果您使用 chrome 或 fiddler 进行检查,响应会怎样?
  • 请求的url是否在同一个域中?
  • @cgatian 更新了问题,是的 anoop 它在同一个域上。
  • @Tarek 你能发布你的回复标题吗?
  • 检查您的服务器日志。它应该包含大量关于失败响应的信息。

标签: javascript jquery ajax httprequest


【解决方案1】:

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

我在 httpd 上找到了一些与堆栈相关的信息(Windows 默认为 1mb,Linux 上默认为 8mb)

我们的产品是 linux 和 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);
                }
            }

【讨论】:

    猜你喜欢
    • 2016-09-07
    • 2014-11-19
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 2022-10-02
    • 2018-02-06
    相关资源
    最近更新 更多