Ajax
Ajax
Ajax
Introduction
Step-1
All modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) have a
built-in XMLHttpRequest object.
variable=new XMLHttpRequest();
Old versions of Internet Explorer (IE5 and IE6) uses an ActiveX Object:
variable=new ActiveXObject("Microsoft.XMLHTTP");
Example
Var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
Step-2
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
Method Description
Step-3
Server Response
Property Description
Example
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
Step-4
200: "OK"
status
404: Page not found
Example
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 &&xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}