简体   繁体   中英

What does “XMLHttpRequest.timeout cannot be set for synchronous http(s) requests made from the window context” mean?

I'm getting some timeouts on a synchronous xml http request in Safari on a Mac. As a workaround, I tried adding a timeout like so:

    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

With the .timeout = 60000 I'm getting a timeout on the .send.

With the .timeout=60000, I'm getting the "XMLHttpRequest.timeout cannot be set for synchronous http(s) requests made from the window context."

I'm not clear on what "XMLHttpRequest.timeout cannot be set for synchronous http(s) requests made from the window context" means. I also found it in mozilla's documentation phrased like so:

Note: You may not use a timeout for synchronous requests with an owning window.

Is there a work-around for this? On the MSDN site I found the following statement regarding Internet Explorer:

If you set an XMLHttpRequest time-out value that is larger than the network stack's time-out value, the network stack will time out first and the ontimeout event will not be raised

-Eric

同步ajax请求的timeout只能从Web Worker使用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM