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 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题