Code:
<html>
<head><title>AJAX Example</title></head>
<script language="javascript">
//Create a Variable the will act as HTTP Request Object
var xmlHttp
//This function LoadPage will request and display the requested page
function LoadPage(){
//This Checks for the browser compatibility
//and makes the xmlHttp variable a HTTP Request Object
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
//Final Touch
var url=prompt("Enter page address?","http://www.yahoo.com","Enter Address")
document.getElementById("txtHint").innerHTML="Loading please wait..."
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
//When new data arrives this function shows the data on the page
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
//Detail code of the function that checks the browser compatibility
//and makes xmlHttp a HTTP Request Object
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
</script>
<body>
<input type=button id="butt" value="Get Page" onclick="LoadPage()"><BR>
<span id="txtHint"></span>
</body>
</html>
Bookmarks