XMLHttpRequest Object Properties

 

Property

Description

onreadystatechange

Used as an event handler for events that trigger upon state changes

readyState

Contains the current state of the object (0: uninitialized, 1: loading, 2: loaded, 3: interactive, 4: complete)

responseText

Returns the response in string format

responseXML

Returns the response in proper XML format

status

Returns the status of the request in numerical format (regular page errors are returned, such as the number 404, which refers to a not found error)

statusText

Returns the status of the request, but in string format (e.g., a 404 error would return the string Not Found)

 

onreadystatechange

The onreadystatechange property is an event handler that allows you to trigger certain blocks of code, or functions, when the state (referring to exactly where the process is at any given time) changes. For example, if you have a function that handles some form of initialization, you could get the main set of functionality you want to fire as soon as the state changes to the complete state.

readyState

The readyState property gives you an in-depth description of the part of the process that the current request is at. This is a highly useful property for exception handling, and can be important when deciding when to perform certain actions. You can use this property to create individual actions based upon how far along the request is. For example, you could have a set of code execute when readyState is loading, or stop executing when readyState is complete.

responseText

The responseText property will be returned once a request has gone through. If you are firing a request to a script of some sort, the output of the script will be returned through this property. With that in mind, most scripts will make use of this property by dumping it into an innerHTML property of an element, thereby asynchronously loading a script or document into a page element.

responseXML

This works similarly to responseText, but is ideal if you know for a fact that the response will be returned in XML format—especially if you plan to use built-in XML-handling browser functionality.

status

This property dictates the response code (a list of common response codes is shown in Table 2-1) that was returned from the request. For instance, if the file requested could not be found, the status will be set to 404 because the file could not be found.

statusText

This property is merely a textual representation of the status property. Where the status property might be set to 404, the statusText would return Not Found. By using both the status and statusText properties together, you can give your user more in-depth knowledge of what has occurred. After all, not many users understand the significance of the number 404.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值