drtwqc3744 2016-07-27 15:16
浏览 105

如何通过jQuery(ajax)跟踪提交给服务器的请求的进度?

I have some PHP app. At the moment I am developing part where an user submits a request/form to the server via ajax (jQuery). Server will insert thousands of records in MySQL database that will probably take couple minutes (due to various calculations etc).

Question: Is there a way to track progress of updates on server side? I understand I can write some output once everything is finished. A workaround would be something like: - store somewhere session ID plus progress details (example: processed 3k inserts out of 5k - maybe in some progress table in database - have front end jQuery script requesting that information from the server every 10 seconds or so...

Any ideas? Please feel free to ask any question you may have. Thank you.

  • 写回答

1条回答 默认 最新

  • dousendun8411 2016-07-27 15:28
    关注

    While I don't know the specifics of what you're doing server-side, a script that takes a "couple minutes" to execute likely involves several distinct steps. It might make sense to have the script execute one step at a time, return its result, and then get called again to execute the next step.

    By using a process like this, you'll be able to track progress client-side. The caveat is that if the client closes the browser window or leaves the page with your ajax code, the remaining steps won't be executed.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog