当前位置: 代码迷 >> Web前端 >> readyState5种状态详解
  详细解决方案

readyState5种状态详解

热度:413   发布时间:2012-10-30 16:13:36.0
readyState五种状态详解
(0) UNINITIALIZED 未初始化
The object has been created but not initialized. (The open method has not been called.)
(XMLHttpRequest)对象已经创建,但尚未初始化(还没有调用open方法)。
(1) LOADING 载入
The object has been created, but the send method has not been called.
(XMLHttpRequest)对象已经创建,但尚未调用send方法。
(2) LOADED 载入完成
The send method has been called, but the status and headers are not yet available.
已经调用send方法,(HTTP响应)状态及头部还不可用。
(3) INTERACTIVE 交互
Some data has been received. Calling the responseBody and responseText properties at this state to obtain partial results will return an error, because status and response headers are not fully available.
已经接收部分数据。但若在此时调用responseBody和responseText属性获取部分结果将会产生错误,因为状态和响应头部还不完全可用。
(4) COMPLETED 完成
All the data has been received, and the complete data is available in the responseBody and responseText properties.
已经接收到了全部数据,并且在responseBody和responseText属性中可以提取到完整的数据。

document.readyState , iframe.onreadyStateaChange,xhr.onreadyStateaChange常用来判断文档dom加载完成和xhr请求状态。xhr中使用readyState  == 4来判断。iframe.readyState =="loaded"和"complete"来判断加载完成。

参考:
http://www.jb51.net/article/16966.htm
  相关解决方案