How do the different browsers handle timeout with synchronous XHR

On Wednesday the AJAXy CRM system I maintain broke for many users, because Firefox started reporting "Use of XMLHttpRequest's timeout attribute is not supported in the synchronous mode in window context" . The other major browsers still work fine so as a workaround I have advised people not to use Firefox.

From what I understand synchronous requests are A Bad Thing, so I can only assume some recent update to Firefox has stopped it from accommodating Bad Things. All previous discussions (here and on the web) imply the use of the timeout attribute with synchronous XMLHttpRequest objects shouldn't work at all, which leads me to wonder why it apparently does (except on Firefox as of Wednesday).

Are the other browsers / old Firefox actually implementing timeout behaviour where they "shouldn't", or do they just ignore the exception and continue execution (rather than bailing out like new Firefox)?

EDIT: I can't get to the code right now but it was along the lines of: if (c.somekindoftimeouthandler !== "unassigned" && this.timeout) {
c.timeout = this.timeout
//more stuff about the handler etc...
}
if (c.somekindoftimeouthandler !== "unassigned" && this.timeout) {
c.timeout = this.timeout
//more stuff about the handler etc...
}
if (c.somekindoftimeouthandler !== "unassigned" && this.timeout) {
c.timeout = this.timeout
//more stuff about the handler etc...
}
where 'this' is come complicated thing presumably inherited from XMLHTTPRequest and 'c' is a specific object referring to the specific AJAX request, or something. I'll come clean that I know little about both Javascript and this specific Sugar-based CRM, but the essence of the code was simple. It was a generic object-oriented way to make requests, and this particular 4-lines or so dealt with when the request timed out. I get the impression this was an abstract base from which specific requests (or requesting entities) were supposed to specialise. The Firefox Javascript engine chokes on the this.timeout .

I believe the thrust of my question is more general though - given the 'badness' of using timeout for synch XHR, how do the various browsers deal with it?


IE allows 'timeout' to work for sync XHR. If the timeout time is reached, it'll throw an exception from send(), I believe.

Firefox implemented exactly what the XHR spec says: timeout is supported on async XHR but not supported for sync XHR (throws if you try to set it).

Other browsers (and old Firefox) don't support timeout at all; they don't even have the property. Since your script is sniffing for whether the property is there, it doesn't even try to set timeout in those other browsers, which is why it works there: your script is not trying to do bad things, so those browsers don't end up throwing an exception.

So all that changed is that Firefox added support for the timeout property, but instead of doing what IE does it implemented what the spec says to do. And your script was assuming that any browser that implements the property will behavior the way IE does...

链接地址: http://www.djcxy.com/p/55328.html

上一篇: AJAX请求异步与异步

下一篇: 不同的浏览器如何处理同步XHR的超时