我在 Mac 上的 Safari 中同步 xml http 请求时遇到一些超时。作为解决方法,我尝试像这样添加超时:
req.open(this.method, fullURL, this.isAsync);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
var params = this.envelopeForm();
req.setRequestHeader("Content-length", params.length);
req.timeout = 60000; //Get the timeut cannot be set here
req.send(params); //Without the above, get a timeout here in Safari
使用 .timeout = 60000 我在 .send 上超时。
使用 .timeout=60000,我收到“无法为从窗口上下文发出的同步 http(s) 请求设置 XMLHttpRequest.timeout。”
我不清楚“无法为从窗口上下文发出的同步 http(s) 请求设置 XMLHttpRequest.timeout”是什么意思。我还在 mozilla 的文档中发现它的措辞如下:
注意:您不能对拥有窗口的同步请求使用超时。
有解决办法吗?在 MSDN 站点上,我发现了以下关于 Internet Explorer 的声明:
如果您设置的 XMLHttpRequest 超时值大于网络堆栈的超时值,网络堆栈将首先超时并且不会引发 ontimeout 事件
-埃里克
最佳答案
timeout
同步 ajax 请求只能用于 web workers
关于javascript - "XMLHttpRequest.timeout cannot be set for synchronous http(s) requests made from the window context"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21487892/