Page 1 of 1

XMLHttpRequest issues

Posted: Wed 23 Nov 2011 12:19 pm
by mcrossley
Normally when I use the XMLHttpRequest object to perform a 'get' with javascript I use something like the following to check the response:

Code: Select all

if (objXML.readyState === 4) { //complete?
  if (objXML.status === 200) {
    //do something
  } else if (objXML.status > 200) {
    //retry
  }
}
In the past XMLHttpRequest.status has always returned an integer/number
Status1.JPG
but I a now seeing a problem where the .status seems to be an error object!
Status2.JPG
which of course messes up the above code - it creates an exception on the first test of status as I am performing a strict comparison.

As a work around I will change to loose comparison, but I cannot find any reference to this via Google. Anyone else seen it before?

Re: XMLHttpRequest issues

Posted: Wed 23 Nov 2011 12:33 pm
by beteljuice
That's a JS 'stackoverflow' from IE9 http://www.google.co.uk/search?q=error+ ... utf-8&aq=t

Re: XMLHttpRequest issues

Posted: Wed 23 Nov 2011 12:42 pm
by mcrossley
doh! now why didn't I Google the error code! :bash: :bash:
For those who are interested in what the problem was: it shows up because an
aborted request comes through with a readyState of "4", which is the same
state as "successful", and we were processing it as such (intentionally - we
check later for successful completion). However, in IE9, when you abort
during an unload, the status, etc, doesn't get set properly, and when you
try and read it an exception is thrown.
So it looks like the request is taking too long and my abort code kicks in creates the problem. I'll look at fixing it...