http/html/ajax:在网站完全处理之前显示结果

发布于 2024-08-27 14:25:11 字数 246 浏览 5 评论 0原文

我正在寻找一种方法,在任务前面的网络应用程序中显示等待消息,并在任务之后隐藏该消息。任务运行时间较长。我不知道这是否可能。

问题是,到目前为止我可以看到,该网站将在任务完成后返回到用户浏览器,因为该任务是网站的一部分,因为内联代码被网络服务器解释器替换(无论是 PHP、Perl 还是任何)。

我能想到的唯一解决方案是将任务与线程或进程并行,并在网站中使用ajax重新查询状态。

有什么想法可以让它变得不那么复杂吗?感谢您的帮助!

I am looking for a way to show in a webapp in front of a task a wait-message and after it hide the message. The task is running a longer time. I dont know if it is possible at all.

The problem is, so far I can see, that the site will be returned to the users browser AFTER the task is completed because the task is part of the site as a inline code replaces by the webserver interpreter (no matter if PHP, Perl or whatever).

The only solution I can imagine is to parallel the task with threads or processes and requery the state with ajax in the website.

Any idea to do it less complex? Thanks for help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼中杀气 2024-09-03 14:25:11

一旦您的代码开始执行,服务器就应该开始向浏览器发送内容;它不会等待服务器端代码先完成。

因此,您可以在渲染包含等待消息的 HTML 后运行该任务。任务完成后,您可以渲染一个隐藏等待消息的

The server should start sending content to the browser as soon as your code starts executing; it does not wait for the server-side code to finish first.

Therefore, you can just run the task after rendering the HTML containing the wait message. After the task, you can render a <script> block that hides the wait message.

橘香 2024-09-03 14:25:11

请参阅通过 CGI 观看长进程。您可以采用相同的技术来使用 AJAX 调用来显示更新。

See Watching long processes through CGI. You could adapt the same technique to display updates using AJAX calls.

左岸枫 2024-09-03 14:25:11

有几种方法可以做到这一点:

1) 将任务拉出到它自己的文件中,这样它就不是内联的。然后使用异步AJAX来查询任务。在事件触发时显示进度条,并在完成后隐藏它。

2) 确保您将数据流回浏览器(这是 php 中的默认设置)。 如果您将 php 作为 CGI 运行,它将在将任何内容返回到浏览器之前执行整个脚本。在这种情况下,您必须 o #1 将内联任务作为页面上的最后一项。在内联任务所在的位置放置一个

内容加载请稍候 或旋转器/进度条。

将内联任务的输出捕获到 php 变量中 在任务末尾添加

Several ways you can do this:

1) Pull the task out into its own file so it isn't inline. Then use asynchronous AJAX to query the task. Display a progress bar on firing of the event, and hide it when it is done.

2) Make sure you are streaming your data back to the browser (This is the default in php.). If you are running php as a CGI it will execute the whole script before returning anything to the browser. In this case you will have to o #1 Put the inline task as the LAST thing on the page. In the place where the inline task is now, put up a <div id=loading>Content Loading Please Wait</div> or spinner/progress bar.

Capture the output of the inline task into a php variable At the end of the task add <script>document.getElementById('loading').innerHTML ="$taskResult";</script>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文