confused — my XMLHttpRequest has readyState of 0 and status of 200
-
03-07-2019 - |
Question
I've set a breakpoint in firebug and am examining my xhr object. Its readyState is 0, its status is 200. My understanding is that if the status is 200, the request should have at least started, and the readystate should be at least 1. Can anyone explain what's going on?
I'm using jquery's $.ajax to create the xhr object, but I wouldn't think that would affect the xhr's readystate and status.
Solution
The request is complete when readyState is 4, not when the status is 200.
OTHER TIPS
The w3c defines that readyState
is a progressive indication of the progress of the xmlhttprequest. It transitions in order from 0->4 (Uninitialized, Open, Sent, Recieving, Loaded) and only at loaded is the content ready to read. This is the point of the property and the reason you monitor the onreadystatechange
event and not status which is a response header.
By the same spec status
is supposed to raise an exception when not available (at recieving or loaded) but I imagine this is flouted by implementation for ease of use.