Re: Problem with XmlHttpRequest (0x80040111 / nsIXMLHttpRequest.status) on several configurations
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Problem with XmlHttpRequest (0x80040111 / nsIXMLHttpRequest.status) on several configurations

From: Thomas 'PointedEars' Lahn <PointedEars@web.de>
Date: Wed Jan 25 2006 - 11:20:04 CET

Arnaud Diederen (aundro wrote:

> Personally, and I have no idea whether it is good practice, I use a
> timeout function.
> For example, if I'm using an XMLHttpRequest, in the
> onreadystatechange() handler, when it comes to setting the
> document.location.href, I'd wrap it in a timeout callback, rather than
> do it directly:
>
> ------------- directly -----------
> req.onreadystatechange = function {
>
> if (req.readyState == 4) {
>
> if (req.status == 200) {
>
> document.location.href = ...
> }
> }
> }
> ----------------------------------
>
>
> ------------- timeout -----------
> req.onreadystatechange = function {
>
> if (req.readyState == 4) {
>
> if (req.status == 200) {
>
> setTimeout (function () {
>
> document.location.href = ...;
> }, 100); // in 100 ms.
> }
> }
> }
> ----------------------------------
>
> That's it.
> Has anyone any comment on whether this is good or bad?

Considering that setTimeout() is unnecessary because the request is
asynchronous already; that using function object references for its
first argument is error-prone because not backwards compatible; that
document.location is deprecated ever since in favor of window.location;
that XMLHttpRequest is a host object that is not cross-browser and not
backwards compatible; that you do not feature-test anything before,
while a simple hyperlink, which in contrast does not depend on support
for client-side scripting, will do exactly the same _better_: it is BAD
-- Broken As Designed.

PointedEars
Received on Tue Feb 7 21:22:20 2006