is this correction correct?
Yes, it is. The open
method, whose specification you have linked, does set the readyState
to OPEN
synchronously. You can test this by simply logging the property value before and after you've called the method. The first loop (with the readyState === UNSENT
) will simply break and not even enter the body, only your corrected one will produce an infinite loop.
Also, is open also asynchronous or just send?
(Assuming an asynchronous request). Both methods return immediately.
open
does set the readystate to OPENED
synchronously. It also synchronously dispatches a readystatechange
event immediately after that (before it returns).
send
does set the sent
flag to true synchronously. There is no "SENT" readystate, so it does not fire an event for that. It does however fire a loadstart
progess event (before it returns).
When the response is asynchronously received, tasks are queued in the event loop to switch the readystate again; these events will be asynchronous.