3

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

Eric
  • 2,861
  • 6
  • 28
  • 59
  • it means you have to wait when using sync. that's just one reason to use async. – dandavis Jan 31 '14 at 18:56
  • But Safari is impatient, it times out, which is why I'm trying to set the .timeout property. – Eric Jan 31 '14 at 19:00
  • there is virtually no situation where async ajax cannot be used where sync ajax can be. that's the ultimate solution. post your code and we can show you how to modify it. – dandavis Jan 31 '14 at 19:32
  • Is there a way to eliminate the owning window or window context? – Eric Feb 03 '14 at 14:37

1 Answers1

0

timeout with synchronous ajax requests can only be used from web workers

Esailija
  • 138,174
  • 23
  • 272
  • 326