dongyun65343 2014-05-22 22:22
浏览 64
已采纳

单击按钮并退出PHP脚本,中止所有AJAX调用

I have a PHP application that does lengthy processing operations on databases. Those operations are processed using AJAX calls. When an AJAX call is triggered, the UI becomes blocked using the JQuery BlockUI Plugin (http://malsup.com/jquery/block/). In the message appearing, I included a button to cancel the request/processing if it is taking too long. I want the following behaviour:

When the "Cancel" button is clicked, all active AJAX calls must be aborted. Then, since the PHP script called is still running on the server side, I will trigger another AJAX call to set a PHP session variable to false. In the PHP script, I am constantly checking for the value of this variable so that if it is false, then I exit() the current script.

Could anyone please give me insight on how I can possibly trigger the aborting of all AJAX calls on pressing a "Cancel" button? In addition, is there a way in a PHP script to launch a separate thread that constantly checks for a session variable's value and accordingly exits all running PHP scripts/functions or at least the current one?

Thanks in advance, Jeremie

  • 写回答

1条回答 默认 最新

  • doucu9677 2014-05-22 22:33
    关注

    You can cancel an ajax request with .abort(). As for terminating PHP when a request is cancelled, you could use ignore_user_abort.

    You could make use of PHP workers to avoid letting users wait until PHP is done, google php workers. You'd find things like IronMQ and others, should be enough to get you going.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题