取消PHP脚本XHR? [英] Cancel PHP script with XHR?
本文介绍了取消PHP脚本XHR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对你的帮助:
function send(){
$.get("/site/send.php", function(data){
alert(data);
}
}
在网站/ send.php我有:
In site/send.php I have:
for($=0;$i++;$i<1000)
sleep(1);
}
echo "OK";
接下来,我在我的js文件:
Next I have in my js file:
send();
$("#click").click(function(){
window.stop(); // this cancel XHR
$.get("/site/reset.php", function(data){
alert(data);
}
})
和在reset.php:
and in reset.php:
echo "RESET";
window.stop();取消我XHR但仍犯规工作正常。我取消XHR,但我仍然必须等待睡眠(1000)在功能上的send()。这并不返回任何东西,但仍继续执行。只有当睡眠> 1000和 /site/reset.php 开始执行。
window.stop(); cancel my XHR but this still doesnt working OK. i cancel XHR, but still i must wait for sleep(1000) in function send(). This doesnt return anything, but still continues to execute. Only if sleep is > 1000 then /site/reset.php begins to execute.
我在这个例子中如何取消PHP函数?
how can i in this example cancel PHP function?
在PHP文件检查可以检查是否XHR仍然使用isset?
is possible check in PHP file check if XHR still isset?
推荐答案
任何一个都可以工作:
ignore_user_abort(false);
for ($=0;$i++;$i<1000) {
if (connection_aborted()) break;
for ($=0;$i++;$i<1000) {
if (connection_status() != CONNECTION_NORMAL) break;
这篇关于取消PHP脚本XHR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文