【发布时间】:2017-02-24 08:02:28
【问题描述】:
我正在实现一个可以监控后台作业的应用程序 (BLAST program)。
我希望当PID等于0时,停止轮询过程。
但在我的长轮询示例中,即使使用abort() 函数,轮询过程也会继续运行。
这个解决方案对我不起作用。
var poll_xhr;
(function doPoll() {
setTimeout(function() {
poll_xhr = $.ajax({
type: 'GET',
url: 'longpoll.php',
error: function (request, textStatus, errorThrown) {
displayError();
},
success: function(result) {
if (result == 0) {
// To kill the AJAX request (Not Working)
console.log("The process is not running.");
poll_xhr.abort();
}
else
console.log(result);
},
dataType: "json",
complete: doPoll,
timeout: 5000
});
})
})();
PHP 代码:
$pid = $_SESSION['PID'];
if(file_exists('/proc/'. $pid)){
// $pid is running
echo json_encode($pid);
}
else{
$e = 0;
echo json_encode($e);
}
如何取消轮询过程?任何建议将不胜感激。
【问题讨论】:
标签: php jquery ajax bioinformatics long-polling