XMLHttpRequest对象的属性-阿里云开发者社区

开发者社区> 老牛的博客> 正文

XMLHttpRequest对象的属性

简介: XMLHttpRequest对象提供了许多属性、方法和事件,因此Ajax脚本可以处理和控制Http请求和响应。
+关注继续查看

XMLHttpRequest对象提供了许多属性、方法和事件,因此Ajax脚本可以处理和控制Http请求和响应。本章的其余部分会对这些进行详细的讨论。

 

The XMLHttpRequest object exposes various properties, methods, and

events so Ajax scripts can process and control HTTP requests and

responses. The rest of this chapter discusses these in detail.

1、 The readyState Property

 

The XMLHttpRequest object cycles through several states as it sends an

HTTP request to the server, waits while the request is processed, and when

it receives a response. So that scripts can respond appropriately to the

various states, the object exposes a readyState property that represents

the object's current state, as shown in Table 1.1.

 

Table 1.1 ReadyState Property Values

ReadyState Property Value       Description

 


0

Represents an “uninitialized” state in which an

XMLHttpRequest object has been created, but

not initialized.

 

 

 

1  

Represents a “sent” state in which code has

called the XMLHttpRequest open() method

and the XMLHttpRequest is ready to send a

request to the server. 

 

 

 

2

 

Represents a “sent” state in which a request

has been sent to the server with the send()

method, but a response has not yet been

received.

 

 

3

 

Represents a “receiving” state in which the

HTTP response headers have been received,

but message body has not yet been completely

received.

 

 

4

 

Represents a “loaded” state in which the

response has been completely received.

 


 

2、 The onreadystatechange Property

 

The   XMLHttpRequest object generates a readystatechange

event      whenever     the      readyState  value      changes.      The

onreadystatechange property accepts an EventListener value,

specifying the method that the object will invoke whenever the

readyState value changes.

 

3、 The responseText Property

 

The responseText property contains the text of the HTTP response

received by the client. When the       readyState value is 0,     1, or 2

responseText contains an empty string. When the       readyState

value is 3 (Receiving), the response contains the incomplete response


received by the client. When           readyState is 4 (Loaded) the

responseText contains the complete response. 

 

4、 The responseXML Property

 

The   responseXML property represents the XML response when the

complete HTTP response has been received (when   readyState is 4),

when the Content-Type header specifies the MIME (media) type as

text/xml, application/xml, or ends in +xml. If the Content-Type

header does not contain one of these media types, the       responseXML

value is   null. The  responseXML value is also   null whenever the

readyState value contains any value other than 4. The responseXML

property value is an object of type Document interface, and represents

the parsed document. If the document cannot be parsed (for example if the

document is malformed or the character encoding of the document is not

supported) the responseXML value is null.

 

5、 The status Property

 

The  status property represents the HTTP status code2 and is of type

short. The status attribute is available only when the        readyState

value is 3 (Receiving) or 4 (Loaded). Attempting to access the status

value when readyState is less than 3 raises an exception.

 

6、 The statusText Property

 

The statusText attribute represents the HTTP status code text and is

also available only when the readyState value is 3 or 4. Attempting to

access the statusText property for other  readyState values raises

an exception.

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/newhappy2008/archive/2009/07/29/4392308.aspx

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Java:jackson将xml和json转为JavaBean对象
Java:jackson将xml和json转为JavaBean对象
24 0
android自定义xmls文件属性
<p style="color:rgb(51,51,51); font-family:Arial; font-size:14px; line-height:26px"> 在使用到自定义View的xml布局文件中需要加入xmlns:前缀=<a target="_blank" href="http://schemas.android.com/apk/res/%E4%BD%A0%E7%9A%8
758 0
.NET对象的XML序列化和反序列化
 序列化的概念 序列化是指一个对象的实例可以被保存,保存成一个二进制串,当然,一旦被保存成二进制串,那么也可以保存成文本串了。比如,一个计数器,数值为2,我们可以用字符串“2”表示。如果有个对象,叫做connter,当前值为2,那么可以序列化成“2”,反向的,也可以从“2”得到值为2的计数器实例。
712 0
+关注
老牛的博客
喜欢研究数据库维护,互联网运营的朋友,可以加我QQ:52234858
519
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载