2012-02-29 43 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调用被调用。

其实我必须先解决服务器重启的问题,这只是解决方法,而不是最好的解决方案。