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

相关文章
|
1月前
|
XML 前端开发 JavaScript
AJAX - 创建 XMLHttpRequest 对象
AJAX - 创建 XMLHttpRequest 对象
|
3月前
|
XML JSON 前端开发
AJAX 中创建 XMLHttpRequest 对象的方法和常用属性、方法
AJAX 中创建 XMLHttpRequest 对象的方法和常用属性、方法
38 0
|
3月前
|
JSON 数据格式
XHR的属性和方法及事件汇总
XHR的属性和方法及事件汇总
36 0
|
XML Web App开发 缓存
一、所谓“神秘”的XMLHttpRequest对象
一、所谓“神秘”的XMLHttpRequest对象
245 0
|
JavaScript 前端开发
javaScript 对象添加属性和创建js对象的方式
javaScript 对象添加属性和创建js对象的方式
424 0
javaScript 对象添加属性和创建js对象的方式
|
JSON JavaScript 前端开发
18、属性描述对象
JavaScript 提供了一个内部数据结构,用来描述对象的属性,控制它的行为,比如该属性是否可写、可遍历等等。这个内部数据结构称为“属性描述对象”(attributes object)。
122 0
|
前端开发
介绍一下XMLHttpRequest对象,他有哪些常用方法和属性
介绍一下XMLHttpRequest对象,他有哪些常用方法和属性
143 0
|
Web App开发 前端开发 JavaScript
XMLHttpRequest对象在IE和Firefox中创建方式有没有不同?
XMLHttpRequest对象在IE和Firefox中创建方式有没有不同?
141 0

热门文章

最新文章