XMLHttpRequest对象的属性

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值