I was reading here that synchronous ajax calls in jquery don't time out.
我在这里读到jquery中的同步ajax调用没有超时。
Is this a technical limitation, or just something the authors didn't feel like supporting? What actually happens under the table when an ajax call is synchronous?
这是技术限制,还是作者不喜欢支持的东西?当ajax调用是同步时,表下实际发生了什么?
3 个解决方案
#1
9
The browser handles synchronous/asynchronous requests via the XMLHttpRequest API, but it does not have a built-in timeout feature. JQuery implements its own timeout in JavaScript on top of the browser XHR API.
浏览器通过XMLHttpRequest API处理同步/异步请求,但它没有内置的超时功能。 JQuery在浏览器XHR API之上实现了自己的JavaScript超时。
Since a synchronous call blocks all running scripts, the JQuery timeout does not work. In theory, it seems like synchronous timeouts would be possible if they were implemented at the browser level, as opposed to the JS level.
由于同步调用会阻止所有正在运行的脚本,因此JQuery超时不起作用。从理论上讲,如果它们是在浏览器级别实现的,那么同步超时似乎是可能的,而不是JS级别。
#2
2
A synchronous AJAX call blocks until the request has been finished. Implementing a timeout is not possible for technical reasons, because the AJAX call would have to be executed later.
同步AJAX调用将阻塞,直到请求完成。由于技术原因,无法实现超时,因为AJAX调用必须在以后执行。
If an AJAX call is executed later, the function somehow has to implement a blocking feature, to stop the code from running further after the AJAX call, and execute it again after a timeout - not possible.
如果稍后执行AJAX调用,该函数必须以某种方式实现阻塞功能,以阻止代码在AJAX调用后进一步运行,并在超时后再次执行 - 不可能。
#3
0
Indeed, is something related to the nature of AJAX request, jQuery cannot modify this.
的确,是与AJAX请求的本质有关的东西,jQuery无法修改这个。
I think timeout should be implemented in the server side in those cases.
我认为在这种情况下应该在服务器端实现超时。
#1
9
The browser handles synchronous/asynchronous requests via the XMLHttpRequest API, but it does not have a built-in timeout feature. JQuery implements its own timeout in JavaScript on top of the browser XHR API.
浏览器通过XMLHttpRequest API处理同步/异步请求,但它没有内置的超时功能。 JQuery在浏览器XHR API之上实现了自己的JavaScript超时。
Since a synchronous call blocks all running scripts, the JQuery timeout does not work. In theory, it seems like synchronous timeouts would be possible if they were implemented at the browser level, as opposed to the JS level.
由于同步调用会阻止所有正在运行的脚本,因此JQuery超时不起作用。从理论上讲,如果它们是在浏览器级别实现的,那么同步超时似乎是可能的,而不是JS级别。
#2
2
A synchronous AJAX call blocks until the request has been finished. Implementing a timeout is not possible for technical reasons, because the AJAX call would have to be executed later.
同步AJAX调用将阻塞,直到请求完成。由于技术原因,无法实现超时,因为AJAX调用必须在以后执行。
If an AJAX call is executed later, the function somehow has to implement a blocking feature, to stop the code from running further after the AJAX call, and execute it again after a timeout - not possible.
如果稍后执行AJAX调用,该函数必须以某种方式实现阻塞功能,以阻止代码在AJAX调用后进一步运行,并在超时后再次执行 - 不可能。
#3
0
Indeed, is something related to the nature of AJAX request, jQuery cannot modify this.
的确,是与AJAX请求的本质有关的东西,jQuery无法修改这个。
I think timeout should be implemented in the server side in those cases.
我认为在这种情况下应该在服务器端实现超时。