2011年(7)
分类: Python/Ruby
2011-06-02 12:43:22
UNSENT (numeric value 0)
The object has been constructed.
OPENED (numeric value 1)The method has been successfully invoked. During this state request headers can be set using and the request can be made using the method.
HEADERS_RECEIVED (numeric value 2)All HTTP headers have been received. Several response members of the object are now available.
LOADING (numeric value 3)The is being received.
DONE (numeric value 4)The data transfer has been completed or something went wrong during the transfer (e.g. infinite redirects).
The state has an associated send() flag that indicates whether the method has been invoked. It can be either true or false and has an initial value of false.
The state has an associated error flag that indicates some type of network error or abortion. It can be either true or false and has an initial value of false.
略加分析,我们可以发现,这两份文档对readyState == 0,1,4的描述基本相同,但对于2和3的描述是完全不同的旧文档中,readyState == 2时,只是已经完成了send()操作,并没有收到任何数据,readyState == 3只是收到了HTTP headers,这样,浏览器大多数时间应该是停在3上,等待数据体和最后的数据处理了,并且readyState == 3时,是不能够处理数据的,新文档中,去除了Sent状态,2状态时所作的事情基本等同于旧文档的2和3状态,即调用了send(),并且只收到了HTTP headers,同时强化了数据接收的状态描述,将数据接收分为了接收数据内容(readyState == [2, 3))和内容处理(readyState == [3, 4))(主要包括null处理,根据Content-Type读取和处理MIME类型,字符集转换和错误处理等工作),也就是说,如果您很清楚返回值的情况的话,那么当readyState == 3时,服务器返回的数据已经完全传输完毕,您就可以自己开始处理数据了。