var xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");xmlHttpReq.open("GET", "http://localhost/books.xml", false);xmlHttpReq.send();
alert(xmlHttpReq.responseText);
var xmlHttpReq = new XMLHttpRequest();
xmlHttpReq.open("GET", "http://localhost/books.xml", false);xmlHttpReq.send();
alert(xmlHttpReq.responseText);
Dim HttpReq As New MSXML2.XMLHTTP30
HttpReq.open "GET", "http://localhost/books.xml", False
HttpReq.send
MsgBox HttpReq.responseText
|
指定当readyState属性改变时的事件处理句柄。只写 | |
|
返回当前请求的状态,只读. | |
|
将回应信息正文以unsigned byte数组形式返回.只读 | |
|
以Ado Stream对象的形式返回响应信息。只读 | |
|
将响应信息作为字符串返回.只读 | |
|
将响应信息格式化为Xml Document对象并返回,只读 | |
|
返回当前请求的http状态码.只读 | |
|
返回当前请求的响应行状态,只读 |
|
取消当前请求 | |
|
获取响应的所有http头 | |
|
从响应信息中获取指定的http头 | |
|
创建一个新的http请求,并指定此请求的方法、URL以及验证信息(用户名/密码) | |
|
发送请求到http服务器并接收回应 | |
|
单独指定请求的某个http头 |
oXMLHttpRequest.onreadystatechange = funcMyHandler;
var xmlhttp=null;
function PostOrder(xmldoc)
{ var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.5.0"); xmlhttp.Open("POST", "http://myserver/orders/processorder.asp", false); xmlhttp.onreadystatechange= HandleStateChange;
xmlhttp.Send(xmldoc);
myButton.disabled = true;
}
function HandleStateChange()
{if (xmlhttp.readyState == 4)
{myButton.disabled = false;
alert("Result = " + xmlhttp.responseXML.xml);}
}
lValue = oXMLHttpRequest.readyState;
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");}
}
|
0 (未初始化) |
对象已建立,但是尚未初始化(尚未调用open方法) |
|
1 (初始化) |
对象已建立,尚未调用send方法 |
|
2 (发送数据) |
send方法已调用,但是当前的状态及http头未知 |
|
3 (数据传送中) |
已接收部分数据,因为响应及http头不全,这时通过responseBody和responseText获取部分数据会出现错误, |
|
4 (完成) |
数据接收完毕,此时可以通过通过responseBody和responseText获取完整的回应数据 |
strValue = oXMLHttpRequest.responseBody;
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");xmlhttp.open("GET", "http://localhost/books.xml", false);xmlhttp.send();
alert(xmlhttp.responseBody);
strValue = oXMLHttpRequest.responseStream;
strValue = oXMLHttpRequest.responseText;
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");xmlhttp.open("GET", "http://localhost/books.xml", false);xmlhttp.send();
alert(xmlhttp.responseText);
var objDispatch = oXMLHttpRequest.responseXML;
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");xmlhttp.open("GET", "http://localhost/books.xml", false);xmlhttp.send();
alert(xmlhttp.responseXML.xml);
lValue = oXMLHttpRequest.status;
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");xmlhttp.open("GET", "http://localhost/books.xml", false);xmlhttp.send();
alert(xmlhttp.status);
|
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 |
strValue = oXMLHttpRequest.statusText;
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");xmlhttp.open("GET", "http://localhost/books.xml", false);xmlhttp.send();
alert(xmlhttp.statusText);
strValue = oXMLHttpRequest.getAllResponseHeaders();
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");xmlhttp.open("GET", "http://localhost/sample.xml", false);xmlhttp.send();
alert(xmlhttp.getAllResponseHeaders());
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
strValue = oXMLHttpRequest.getResponseHeader(bstrHeader);
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");xmlhttp.open("GET", "http://localhost/sample.xml", false);xmlhttp.send();
alert(xmlhttp.getResponseHeader("Server"));oXMLHttpRequest.open(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword);
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);
oXMLHttpRequest.send(varBody);
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");xmlhttp.open("GET", "http://localhost/sample.xml", false);xmlhttp.send();
alert(xmlhttp.responseXML.xml);
oXMLHttpRequest.setRequestHeader(bstrHeader, bstrValue);