Hello,
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.
thanks,
-Morgan
-
The request is complete when readyState is 4, not when the status is 200.
Nerdling : Status 200 can happen before you get any meaningful data back: It's just a header.morgancodes : But does it make sense for readystate to be 0 in that case?Luca Matteis : morgancodes: if you set the breakpoint too early, yes.morgancodes : @Luca Fair enough. Thanks. My code works now, I'll consider the mystery as-solved-as-I-need-it-to-be. -
The w3c defines that
readyStateis 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 theonreadystatechangeevent and not status which is a response header.By the same spec
statusis supposed to raise an exception when not available (at recieving or loaded) but I imagine this is flouted by implementation for ease of use.Luca Matteis : "at recieving or loaded" ? Status should only be available on `loaded`.annakata : From the spec: "It MUST be available when readyState is 3 (Receiving) or 4 (Loaded)."
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.