2.3.09

Ajax

1 - Create 2 file are testAjax.htm and time.asp


2 - Code for testAjax.html are:

<body>
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.asp",true);
xmlHttp.send(null);
}
</script>
<form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time">
</form>
</body>
</html>




3 - Code for time.asp are:
<% response.expires=-1 response.write(time) %>



4 - Copy 2 file testAjax.htm and time.asp to C:\Inetpub\wwwroot\TestAjax folder
5 - Click Control Panel ----> Administrative Tools -----> Internet Information Services ------> local computer ------> Web Site -------> Default Web Site (Right Click) -------> Start
6 - Type address http://localhost/New%20Folder/testAjax.htm in browser
7 - Input Name
8 - View time auto change in TimeTextField when NameTextField change


Note:
*****If don't have C:\Inetpub folder
-----> Add or Remove Programs ----> Add/Remove Windows Components ------> checked IIS -----> input SetupWindow disc -----> Ok
*****Tags html is false. You edit please

No comments:

Post a Comment