2012-02-29 18 views
0

我知道在服務器上運行的應用程序中的錯誤以及調用的操作斷開所有HTTP客戶端。我需要在服務器上調用這個功能,但是我無法修復這個錯誤。 這裏是我的服務器代碼:當以前的AJAX調用由於連接失敗而未能完全關閉時運行jQuery AJAX調用

<?php 
// file: run_script.php 
shell_exec('close_all_HTTP_connections_error '.$_REQUEST['params']); 
?> 

我試圖找到通過AJAX調用的解決方法,我知道調用失敗,但用戶不會看到錯誤,如ERR_EMPTY_RESPONSE。我的問題是我需要對服務器進行另一次調用(不會出現正常的失敗)。第二個電話沒有發送到服務器,因爲我猜想以前的電話失敗。 這裏是我的jQuery的AJAX調用:

function sendData(url, step) { 
    $.ajax({ 
    type: 'POST', 
    async: true, 
    url: url, 
    headers: { // I try it without this also 
     'Connection' : 'close' 
    }, 
    data: { 
     'params' : 'bla bla' 
    }, 
    complete: function(jqXHR, textStatus) { 
     console.log(jqXHR); 
     console.log(textStatus); 
     if (step < 2) { 
     sendData('another.php', step+1); 
     } 
     else { 
     console.log("done"); 
     // go forward 
     } 
    }, 
    dataType: 'html' 
    }); 
} 

$(document).ready(function() { 
    sendData('run_script.php', 1); 
}); 

這裏是Chrome檢查我的屏幕截圖:

enter image description here

和HTTP請求:

run_script.php:

POST http://?????.com/test/run_script.php HTTP/1.1 
Origin: http://?????.com 
X-Requested-With: XMLHttpRequest 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.22 (KHTML, like Gecko) 
Chrome/19.0.1049.3 Safari/535.22 
Content-Type: application/x-www-form-urlencoded 
Accept: text/html, */*; q=0.01 
Referer: http://?????.com/test/result.php 
params:bla bla 

another.php:

POST http://?????.com/test/another.php HTTP/1.1 
Origin: http://?????.com 
X-Requested-With: XMLHttpRequest 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.22 (KHTML, like Gecko) 
Chrome/19.0.1049.3 Safari/535.22 
Content-Type: application/x-www-form-urlencoded 
Accept: text/html, */*; q=0.01 
Referer: http://?????.com/test/result.php 
params:bla bla 

當然沒有HTTP響應。

回答

0

問題是,以前在服務器上重新啓動服務器時調用該任務。然後我需要等待下一個AJAX調用被調用。

其實我必須先解決服務器重啓的問題,這只是解決方法,而不是最好的解決方案。