2013-02-28 263 views
0

我有一個沉重的應用程序,一切都在阿賈克斯。失敗的http請求

現在有一次,當一個頁面加載時,有10多個Ajax請求,其中一些對我來說因爲一個未知的原因而隨機失敗。

無論如何要知道爲什麼這些請求失敗?

我可以捕獲錯誤裏面的錯誤:{}情況下,我應該再次調用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); 
} 

但是,這可能會造成系統崩潰,如果阿賈克斯總是失敗...

更新#3

我認爲它更多的是WAMP問題,因爲我沒有這些生產錯誤。

無論如何,謝謝大家的努力!

+0

請告訴我回應說,如果你檢查使用Chrome或拉琴? – cgatian 2013-02-28 12:41:36

+3

請求的網址是否在同一個域中? – 2013-02-28 12:45:42

+0

@cgatian更新了這個問題,並且是在同一個域上的anoop。 – Tarek 2013-02-28 12:47:10

回答

0

問題與Windows上的Apache有關,原因不明服務器隨機崩潰。

我發現棧上的httpd相關的一些信息(1MB Windows默認VS 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); 
       } 
      }