XMLHttpRequest
- A JavaScript Class that lets you make asynchronous HTTP requests from JavaScript
- Make an HTTP request from a JavaScript event
- A call back JavaScript function is invoked at each state of the HTTP request and response
XMLHttpRequest Properties
- onreadystatechange - call back function for state changes
- readyState - the current state of the HTTP call
- responseText - the text result of the request
- responseXML - DOM xml object from the request
- status - HTTP status code of the response
- statusText - HTTP status text
XMLHttpRequest Example from sample #1:
var xmlHttpRequest;
function getXmlHttpRequestObject()
{
if(window.ActivexObject)
{
return (new ActivexObject("Microsoft.XMLHTTP"));
}
else if( window.XMLHttpRequest)
{
return(new XMLHttpRequest());
}
else
{
return null;
}
}
function sendRequest() {
xmlHttpRequest = getXmlHttpRequestObject();
xmlHttpRequest.onreadystatechange = handleResponse;
xmlHttpRequest.open("GET", "data_message.html", true);
xmlHttpRequest.send(null);
}
function handleResponse() {
if (xmlHttpRequest.readyState == 4) {
alert(xmlHttpRequest.responseText);
}
}
IE does it different
- The above example however won't work on IE
new ActiveXOjbect("Microsoft.XMLHTTP");- Native XMLHttpRequest support should be in IE7
Source :
No comments:
Post a Comment