Index.asp:
Program code
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>ajax Simple Application </title>
<script language= "JavaScript" >
Creating XMLHttpRequest Objects
var request = false;
try {
Request = new XMLHttpRequest ();
} catch (Trymicrosoft) {
try {
Request = new ActiveXObject ("Msxml2.xmlhttp");
} catch (Othermicrosoft) {
try {
Request = new ActiveXObject ("Microsoft.XMLHTTP");
} catch (Failed) {
Request = false;
}
}
}
if (!request) alert ("Error initializing xmlhttprequest!");
Get information
function GetInfo () {
var url = "info.asp?id=" + math.random ();
Request.open ("Get", url, True);
Request.onreadystatechange = Updatepage;
Request.send (NULL);
}
Update page
function Updatepage () {
if (request.readystate = = 4) {
if (Request.status = = 200) {
var response = Request.responsetext;
document.getElementById ("Div1"). innertext = response;
}else if (request.status = = 404) {
Alert ("Requested URL is not found.");
else if (Request.status = 403) {
Alert ("Access denied.");
} else
Alert ("Status is" + Request.status);
}
}
</script>
<body>
<input name= "btn" type= "button" id= "BTN" value= "to obtain" onclick= "GetInfo ();"/>
<div id= "Div1" > here Displays the contents of the new div tag </div>
</body>