XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext

Similar documents
目 录(目录名)


穨control.PDF

Chn 116 Neh.d.01.nis

IP505SM_manual_cn.doc

ebook140-9

PowerPoint 演示文稿

epub 61-2

Important Notice SUNPLUS TECHNOLOGY CO. reserves the right to change this documentation without prior notice. Information provided by SUNPLUS TECHNOLO

untitled

RUN_PC連載_10_.doc

Microsoft Word - 01.DOC

Fun Time (1) What happens in memory? 1 i n t i ; 2 s h o r t j ; 3 double k ; 4 char c = a ; 5 i = 3; j = 2; 6 k = i j ; H.-T. Lin (NTU CSIE) Referenc

3.1 num = 3 ch = 'C' 2

RPC SOAP REST API API HTTP JSON XML PHP PHP PHP PHP PHP HTTP request/response cycle HTTP HTTP verbs headers Cookies JSON XML PHP RPC SOAP RESTful HTTP

1 目 錄 1. 簡 介 一 般 甄 試 程 序 第 一 階 段 的 準 備 第 二 階 段 的 準 備 每 間 學 校 的 面 試 方 式 各 程 序 我 的 做 法 心 得 及 筆 記 結 論..

Go构建日请求千亿微服务最佳实践的副本

Microsoft PowerPoint - ch6 [相容模式]


UDC The Design and Implementation of a Specialized Search Engine Based on Robot Technology 厦门大学博硕士论文摘要库

untitled

RunPC2_.doc

Kubenetes 系列列公开课 2 每周四晚 8 点档 1. Kubernetes 初探 2. 上 手 Kubernetes 3. Kubernetes 的资源调度 4. Kubernetes 的运 行行时 5. Kubernetes 的 网络管理理 6. Kubernetes 的存储管理理 7.

「人名權威檔」資料庫欄位建置表

BC04 Module_antenna__ doc

WWW PHP

1.JasperReport ireport JasperReport ireport JDK JDK JDK JDK ant ant...6

C3_ppt.PDF

(Methods) Client Server Microsoft Winsock Control VB 1 VB Microsoft Winsock Control 6.0 Microsoft Winsock Control 6.0 1(a). 2

ebook4-12

( Version 0.4 ) 1

ch_code_infoaccess


27 :OPC 45 [4] (Automation Interface Standard), (Costom Interface Standard), OPC 2,,, VB Delphi OPC, OPC C++, OPC OPC OPC, [1] 1 OPC 1.1 OPC OPC(OLE f

財金資訊-80期.indd

關於本書 Part 3 CSS XHTML Ajax Part 4 HTML 5 API JavaScript HTML 5 API Canvas API ( ) Video/Audio API ( ) Drag and Drop API ( ) Geolocation API ( ) Part 5

XXXXXXXX

1 SQL Server 2005 SQL Server Microsoft Windows Server 2003NTFS NTFS SQL Server 2000 Randy Dyess DBA SQL Server SQL Server DBA SQL Server SQL Se

final

「西醫基層總額支付委員會《第28次委員會議紀錄

國家圖書館典藏電子全文

SA-DK2-U3Rユーザーズマニュアル

Microsoft Word - SupplyIT manual 3_cn_david.doc

Bus Hound 5

Logitech Wireless Combo MK45 English

無障礙網頁開發規範二版(草案)

untitled

jsp

QQGQ2.E Power Supplies, Information Technology Equipment Including Ele... 1/10

1

声 明 本 公 司 及 全 体 董 事 监 事 高 级 管 理 人 员 承 诺 不 存 在 任 何 虚 假 记 载 误 导 性 陈 述 或 重 大 遗 漏, 并 对 其 真 实 性 准 确 性 完 整 性 承 担 个 别 和 连 带 的 法 律 责 任 本 公 司 负 责 人 和 主 管 会 计 工

untitled

國家圖書館典藏電子全文

IBM Rational ClearQuest Client for Eclipse 1/ IBM Rational ClearQuest Client for Ecl

* RRB *

第一章

Professional Ajax Ajax Adaptive Path, LLC Jesse James Garrett Ajax php Garrett WebG

ebook37-11

WebSphere Studio Application Developer IBM Portal Toolkit... 2/21 1. WebSphere Portal Portal WebSphere Application Server stopserver.bat -configfile..

CANVIO_AEROCAST_CS_EN.indd

PowerPoint Presentation

TopTest_Adminstrator.doc

HC50246_2009

Microsoft Word - 王彬_已修改_.doc

获取 Access Token access_token 是接口的全局唯一票据, 接入方调用各接口时都需使用 access_token 开发者需要进行妥善保存 access_token 的存储至少要保留 512 个字符空间 access_token 的有效期目前为 2 个小时, 需定时刷新, 重复

AI-AUTO-011 Saflex® Advanced PVB - Color Interlayer (Chinese)

Microsoft PowerPoint - Aqua-Sim.pptx

Guava学习之Resources

ebook140-8

ebook65-20

4. 每 组 学 生 将 写 有 习 语 和 含 义 的 两 组 卡 片 分 别 洗 牌, 将 顺 序 打 乱, 然 后 将 两 组 卡 片 反 面 朝 上 置 于 课 桌 上 5. 学 生 依 次 从 两 组 卡 片 中 各 抽 取 一 张, 展 示 给 小 组 成 员, 并 大 声 朗 读 卡

RUN_PC連載_12_.doc

2015年4月11日雅思阅读预测机经(新东方版)

Mechanical Science and Technology for Aerospace Engineering October Vol No. 10 Web SaaS B /S Web2. 0 Web2. 0 TP315 A

1 Internet [1]P Web Service Web Service Web XML HTTP URL 1..NET Framework.NET Framework Web Service HTTP 80.NET Framework 2

untitled

SiteView技术白皮书

PowerPoint 演示文稿

ext-web-auth-wlc.pdf

Transcription:

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

abort 取消当前请求

语法 oxmlhttprequest.abort();

备注 调用此方法后, 当前请求返回 UNINITIALIZED 状态

参考 readystate 属性 open 方法

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

getallresponseheaders 获取响应的所有 http 头

语法 strvalue = oxmlhttprequest.getallresponseheaders();

Example var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0"); xmlhttp.open("get", "http://localhost/sample.xml", false); xmlhttp.send(); alert(xmlhttp.getallresponseheaders()); 输出由 web 服务器返回的 http 头信息,example: Server:Microsoft-IIS/5.1 X-Powered-By:ASP.NET Date:Sat, 07 Jun 2003 23:23:06 GMT Content-Type:text/xml Accept-Ranges:bytes Last Modified:Sat, 06 Jun 2003 17:19:04 GMT ETag:"a0e2eeba4f2cc31:97f" Content-Length:9

备注 每个 http 头名称和值用冒号分割, 并以 \r\n 结束 当 send 方法完成后才可调用该方法

参考 send 方法 getresponseheader 方法 setrequestheader 方法

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

getresponseheader 从响应信息中获取指定的 http 头

语法 strvalue = oxmlhttprequest.getresponseheader(bstrheader);

Example var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0"); xmlhttp.open("get", "http://localhost/sample.xml", false); xmlhttp.send(); alert(xmlhttp.getresponseheader("server")); 输出 http 头中的 server 列 : 当前 web 服务器的版本及名称

备注 当 send 方法成功后才可调用该方法 如果服务器返回的文档类型为 "text/xml", 则这句话 xmlhttp.getresponseheader("content-type"); 将返回字符串 "text/xml" 可以使用 getallresponseheaders 方法获取完整的 http 头信息

参考 send 方法 getallresponseheaders 方法 setrequestheader 方法

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

onreadystatechange 指定当 readystate 属性改变时的事件处理句柄

语法 oxmlhttprequest.onreadystatechange = funcmyhandler;

Example 如下的例子演示当 XMLHTTPRequest 对象的 readystate 属性改变时调用 HandleStateChange 函数, 当数据接收完毕后 (readystate == 4) 此页面上的一个按钮将被激活 var xmlhttp=null; function PostOrder(xmldoc) { var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.5.0"); xmlhttp.open("post", "http://myserver/orders/processorder.asp", fa xmlhttp.onreadystatechange= HandleStateChange; xmlhttp.send(xmldoc); mybutton.disabled = true; } function HandleStateChange() { if (xmlhttp.readystate == 4) { mybutton.disabled = false; alert("result = " + xmlhttp.responsexml.xml); } }

备注 此属性只写, 为 W3C 文档对象模型的扩展.

参考 readystate 属性

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

open 创建一个新的 http 请求, 并指定此请求的方法 URL 以及验证信息

语法 oxmlhttprequest.open(bstrmethod, bstrurl, varasync, bstruser, bstrpa

参数 bstrmethod http 方法, 例如 :POST GET PUT 及 PROPFIND 大小写不敏感 bstrurl 请求的 URL 地址, 可以为绝对地址也可以为相对地址 varasync[ 可选 ] 布尔型, 指定此请求是否为异步方式, 默认为 true 如果为真, 当状态改变时会调用 onreadystatechange 属性指定的回调函数 bstruser[ 可选 ] 如果服务器需要验证, 此处指定用户名, 如果未指定, 当服务器需要验证时, 会弹出验证窗口 bstrpassword[ 可选 ] 验证信息中的密码部分, 如果用户名为空, 则此值将被忽略

Example 下面的例子演示从服务器请求 book.xml, 并显示其中的 book 字段 var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0"); xmlhttp.open("get","http://localhost/books.xml", false); xmlhttp.send(); var book = xmlhttp.responsexml.selectsinglenode("//book[@id='bk101'] alert(book.xml);

备注 调用此方法后, 可以调用 send 方法向服务器发送数据

参考 abort 方法 onreadystatechange 属性 XMLHTTPRequest 对象

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

readystate 返回 XMLHTTP 请求的当前状态

语法 lvalue = oxmlhttprequest.readystate;

Example var XmlHttp; XmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0"); function send() { XmlHttp.onreadystatechange = dohttpreadystatechange; XmlHttp.open("GET", "http://localhost/sample.xml", true); XmlHttp.send(); } function dohttpreadystatechange() { if (XmlHttp.readyState == 4) { alert("done"); } }

备注 变量, 此属性只读, 状态用长度为 4 的整型表示. 定义如下 : 0 ( 未初始化 ) 对象已建立, 但是尚未初始化 ( 尚未调用 open 方法 ) 1 ( 初始化 ) 对象已建立, 尚未调用 send 方法 2 ( 发送数据 ) send 方法已调用, 但是当前的状态及 http 头未知 3 ( 数据传送中 ) 已接收部分数据, 因为响应及 http 头不全, 这时通过 responsebody 和 responsetext 获取部分数据会出现错误, 数据接收完毕, 此时可以通过通过 responsebody 和 responsetext 4 ( 完成 ) 获取完整的回应数据

参考 open 方法 responsebody 属性 responsetext 属性 send 方法 status 属性 statustext 属性

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

responsebody 返回某一格式的服务器响应数据

语法 strvalue = oxmlhttprequest.responsebody;

Example var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0"); xmlhttp.open("get", "http://localhost/books.xml", false); xmlhttp.send(); alert(xmlhttp.responsebody);

备注 变量, 此属性只读, 以 unsigned array 格式表示直接从服务器返回的未经解码的二进制数据

参考 responsestream 属性 responsetext 属性 responsexml 属性

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

responsestream 以 Ado Stream 对象的形式返回响应信息

语法 strvalue = oxmlhttprequest.responsestream;

备注 变量, 此属性只读, 以 Ado Stream 对象的形式返回响应信息

参考 responsebody 属性 responsetext 属性 responsexml 属性

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

responsetext 将响应信息作为字符串返回

语法 strvalue = oxmlhttprequest.responsetext;

Example var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0"); xmlhttp.open("get", "http://localhost/books.xml", false); xmlhttp.send(); alert(xmlhttp.responsetext);

备注 变量, 此属性只读, 将响应信息作为字符串返回 XMLHTTP 尝试将响应信息解码为 Unicode 字符串,XMLHTTP 默认将响应数据的编码定为 UTF-8, 如果服务器返回的数据带 BOM(byte-order mark),xmlhttp 可以解码任何 UCS-2 (big or little endian) 或者 UCS-4 数据 注意, 如果服务器返回的是 xml 文档, 此属性并不处理 xml 文档中的编码声明 你需要使用 responsexml 来处理

参考 responsebody 属性 responsetext 属性 responsexml 属性

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

responsexml 将响应信息格式化为 Xml Document 对象并返回

语法 var objdispatch = oxmlhttprequest.responsexml;

Example var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0"); xmlhttp.open("get", "http://localhost/books.xml", false); xmlhttp.send(); alert(xmlhttp.responsexml.xml);

备注 变量, 此属性只读, 将响应信息格式化为 Xml Document 对象并返回 如果响应数据不是有效的 XML 文档, 此属性本身不返回 XMLDOMParseError, 可以通过处理过的 DOMDocument 对象获取错误信息

参考 responsebody 属性 responsestream 属性 responsetext 属性

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

send 发送请求到 http 服务器并接收回应

语法 oxmlhttprequest.send(varbody);

参数 varbody 欲通过此请求发送的数据

Example xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0"); xmlhttp.open("get", "http://localhost/sample.xml", false); xmlhttp.send(); alert(xmlhttp.responsexml.xml);

备注 此方法的同步或异步方式取决于 open 方法中的 basync 参数, 如果 basync == False, 此方法将会等待请求完成或者超时时才会返回, 如果 basync == True, 此方法将立即返回 This method takes one optional parameter, which is the requestbody to use. The acceptable VARIANT input types are BSTR, SAFEARRAY of UI1 (unsigned bytes), IDispatch to an XML Document Object Model (DOM) object, and IStream *. You can use only chunked encoding (for sending) when sending IStream * input types. The component automatically sets the Content-Length header for all but IStream * input types. 如果发送的数据为 BSTR, 则回应被编码为 utf-8, 必须在适当位置设置一个包含 charset 的文档类型头 If the input type is a SAFEARRAY of UI1, the response is sent as is without additional encoding. The caller must set a Content-Type header with the appropriate content type. 如果发送的数据为 XML DOM object, 则回应将被编码为在 xml 文档中声明的编码, 如果在 xml 文档中没有声明编码, 则使用默认的 UTF-8 If the input type is an IStream *, the response is sent as is without additional encoding. The caller must set a Content-Type header with the appropriate content type.

参考 open 方法 XMLHTTPRequest 对象

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

setrequestheader 单独指定请求的某个 http 头

语法 oxmlhttprequest.setrequestheader(bstrheader, bstrvalue);

参数 bstrheader 字符串, 头名称 bstrvalue 字符串, 值

备注 如果已经存在已此名称命名的 http 头, 则覆盖之 此方法必须在 open 方法后调用

参考 getallresponseheaders 方法 XMLHTTPRequest 对象

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

status 返回当前请求的 http 状态码

语法 lvalue = oxmlhttprequest.status;

Example var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0"); xmlhttp.open("get", "http://localhost/books.xml", false); xmlhttp.send(); alert(xmlhttp.status);

返回值 长整形标准 http 状态码, 定义如下 : Number Description 100 Continue 101 Switching protocols 200 OK 201 Created 202 Accepted 203 Non-Authoritative Information 204 No Content 205 Reset Content 206 Partial Content 300 Multiple Choices 301 Moved Permanently 302 Found

303 See Other 304 Not Modified 305 Use Proxy 307 Temporary Redirect 400 Bad Request 401 Unauthorized 402 Payment Required 403 Forbidden 404 Not Found 405 Method Not Allowed 406 Not Acceptable 407 Proxy Authentication Required 408 Request Timeout

409 Conflict 410 Gone 411 Length Required 412 Precondition Failed 413 Request Entity Too Large 414 Request-URI Too Long 415 Unsupported Media Type 416 Requested Range Not Suitable 417 Expectation Failed 500 Internal Server Error 501 Not Implemented 502 Bad Gateway 503 Service Unavailable

504 Gateway Timeout 505 HTTP Version Not Supported

备注 长整形, 此属性只读, 返回当前请求的 http 状态码, 此属性仅当数据发送并接收完毕后才可获取

参考 statustext 属性 send 方法

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

statustext 返回当前请求的响应行状态

语法 strvalue = oxmlhttprequest.statustext;

Example var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0"); xmlhttp.open("get", "http://localhost/books.xml", false); xmlhttp.send(); alert(xmlhttp.statustext);

备注 字符串, 此属性只读, 以 BSTR 返回当前请求的响应行状态, 此属性仅当数据发送并接收完毕后才可获取

参考 status 属性 send 方法

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

XMLHttpRequest 提供客户端同 http 服务器通讯的协议

Example 下面的代码是在 JScript 中创建一个 XMLHTTP 对象并从服务器请求一个 XML 文档 服务器返回 XML 文档并显示 var xmlhttpreq = new ActiveXObject("MSXML2.XMLHTTP.3.0"); xmlhttpreq.open("get", "http://localhost/books.xml", false); xmlhttpreq.send(); alert(xmlhttpreq.responsetext); 在非 IE 的浏览器中, 需要用 new XMLHttpRequest() 来创建对象, 如下 : var xmlhttpreq = new XMLHttpRequest(); xmlhttpreq.open("get", "http://localhost/books.xml", false); xmlhttpreq.send(); alert(xmlhttpreq.responsetext); vbscript: Dim HttpReq As New MSXML2.XMLHTTP30 HttpReq.open "GET", "http://localhost/books.xml", False HttpReq.send MsgBox HttpReq.responseText

备注 客户端可以通过 XmlHttp 对象 (MSXML2.XMLHTTP.3.0) 向 http 服务器发送请求并使用微软 XML 文档对象模型 Microsoft XML Document Object Model (DOM) 处理回应

参考 XMLHTTPRequest 成员

XMLHTTP 对象参考 XMLHTTPRequest 对象 XMLHTTPRequest 成员 onreadystatechange readystate responsebody responsestream responsetext responsexml status statustext abort getallresponseheaders getresponseheader open send setrequestheader

XMLHttpRequest 成员 属性 指定当 readystate 属性改变时的事件处理句柄 只 onreadystatechange* 写 readystate 返回当前请求的状态, 只读. responsebody 将回应信息正文以 unsigned byte 数组形式返回. 只读 responsestream 以 Ado Stream 对象的形式返回响应信息 只读 responsetext 将响应信息作为字符串返回. 只读 responsexml 将响应信息格式化为 Xml Document 对象并返回, 只读 status 返回当前请求的 http 状态码. 只读 statustext 返回当前请求的响应行状态, 只读 * 表示此属性是 W3C 文档对象模型的扩展.

方法 abort 取消当前请求 getallresponseheaders 获取响应的所有 http 头 getresponseheader 从响应信息中获取指定的 http 头 open 创建一个新的 http 请求, 并指定此请求的方法 URL 以及验证信息 ( 用户名 / 密码 ) send 发送请求到 http 服务器并接收回应 setrequestheader 单独指定请求的某个 http 头

事件 无

参考 XMLHTTPRequest