Python 和 jQuery.ajax 调用之间的进度更新

发布于 2024-11-25 15:55:34 字数 468 浏览 3 评论 0原文

我需要运行两个函数,这两个函数都需要相当长的时间才能完成。第二个依赖于第一个,因此它们需要按顺序排列。第一个必须通过从 JavaScript 对 Python 的 ajax 调用来完成(使用 jquery.ajax)。第二个是一些解析和 HTML 生成,因此可以用 JavaScript 或 Python 来完成。

我更喜欢第二个使用Python,因为这意味着“繁重的工作”是在服务器端完成的。但是,我想通知用户第一个功能已完成,第二个功能正在运行。问题是函数之间的数据量对于从 Python 传输到 JavaScript(服务器到客户端),然后返回到 Python(客户端到服务器)没有意义。将所有内容保留在服务器端直到第二个函数完成,然后将我所拥有的信息传输回 JavaScript(包含 HTML 代码)会更快。

再次,我想通知用户(通过 JavaScript)第一个 Python 函数已完成,第二个函数正在运行。然后,一旦第二个完成,数据应该传回 JavaScript 进行显示。

I have two functions that I need to run, both take quite some time to complete. The second is dependent on the first, so they need to be in order. The first MUST be done with an ajax call to Python from JavaScript (using jquery.ajax). The second is some parsing and HTML generation, so it can be done in either JavaScript or Python.

I would prefer the second to be in Python since this would mean the "heavy lifting" is done server-side. However, I would like to notify the user that the first function is complete and the second one is running. The problem is the amount of data between the functions would not make sense to transfer from Python to JavaScript (server to client), then back to Python (client to server). It'd be much faster to keep everything on the server side until the second function is complete, then transfer what information I do have back to JavaScript (containing the HTML code).

Again, I would like to notify the user (through JavaScript) that the first Python function is complete and the second one is running. Then once the second one completes, the data should be passed back to JavaScript to be displayed.

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

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

发布评论

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

评论(1

小ぇ时光︴ 2024-12-02 15:55:34

您可以将 python 部分分成 2 个函数并首先调用,然后在第一个函数完成后调用第二个函数,使用 jQuery.ajax(...)

或者使用 HTML5 Web Sockets 与服务器讨论...

You can cut the python part in 2 functions and call first, then call 2nd when first is finished all with jQuery.ajax(...)

Or use HTML5 Web Sockets to discuss with server...

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