系统操作的 AJAX 请求会阻塞 AJAX 调用的页面剩余部分
我有一堆 AJAX 请求,第一个是一个
$.post("go.php", { url: pastedURL, key: offskey, mo: 'inward', id: exID});
This 请求,在 go.php 中包含一个系统命令,尽管最后有 nohup 和 & ,但它并没有不要停止 Firebug 上的旋转 - 等待响应。
不幸的是,下一个 AJAX 请求
$.post("requestor.php", { request: 'getProgress', key: offskey}, function(data) { console.log(data.response); }, "json");
不会运行,它在 firebug 中旋转(我猜直到 go.php 完成) - 它最终会超载所有内容(这是在计时器上每隔几秒检查一次)。
所以我想问题是,是否有一个 AJAX 方法可以简单地抛出数据并走开,而不是等待响应......或者以某种方式我可以在另一个请求等待时执行另一个请求。
希望有人知道我的意思。
I have a bunch of AJAX requests, the first is a
$.post("go.php", { url: pastedURL, key: offskey, mo: 'inward', id: exID});
This request, in go.php includes a system command, which despite nohup and & at the end, doesn't stop whirling on Firebug - waiting for response.
Unfortunately, the next AJAX request
$.post("requestor.php", { request: 'getProgress', key: offskey}, function(data) { console.log(data.response); }, "json");
Doesn't run, it whirls round in firebug (i'm guessing until go.php has finished) - it overloads everything eventually (this is on a timer to check every few seconds).
So I guess the question is, is there an AJAX method which simply throws data and walks away, instead of waiting for response... or someway I can perform another request whilst the other is waiting.
Hope someone knows what I mean.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查
async: false,
作为 jQuery 中$.ajax()
方法的参数。您需要将其设置为
async: true
。Check for
async: false,
as parameter for$.ajax()
method in jQuery.You need it to be set
async: true
.事实证明,另一端的 PHP 请求需要这样才能继续等待:-
来源
Turns out the PHP request on the other end would need this in order to proceed with waiting:-
source
浏览器使用的连接数量有限。该数量因浏览器而异,但对于 IE7 等较旧的浏览器,每个服务器的连接数可能只有 2 个。一旦您用待处理的请求填充了它们,您就必须等待这些请求完成,然后才能向该服务器发出任何其他请求。
听起来您可能在前面的请求完成之前使用 setTimeout 或 setInterval 发出额外的 requestor.php 请求?如果是这样,请不要这样做。使用完整的 $.ajax (可能也有超时)并在成功/错误回调中才发出另一个请求。
There are a limited number of connections used by the browser. The number varies by browser, but for older ones like IE7 it can be as little as 2 connections per server. Once you fill them with pending requests you have to wait for those to complete before you can make any additional requests to that server.
It sounds like you may be making additional requestor.php requests using setTimeout or setInterval before the previous ones have finished? If so, don't do that. Use a full $.ajax (perhaps with a timeout as well) and in the success/error callback only then make another request.