1. Different browsers
create XMLHttpRequest object methods (functions generic)
<Script type = "text / JavaScript">
function the ajaxFunction ()
{
var
the try
{
// Firefox, Opera 8.0+, Safari
}
the catch (E)
{
/ / Internet Explorer
the try
{
// IE 6.0+
}
the catch (E)
{
the try
{
// IE 5.5+
}
the catch (E)
{
Alert ( "your browser does not support AJAX!");
return false;
}
}
}
}
</ Script>
2. a simple Ajax application example
<HTML>
<body>
<Script type = "text / JavaScript">
function the ajaxFunction ()
{
var
the try
{
// Firefox, Opera 8.0+, Safari
}
the catch (E)
{
// Internet Explorer
the try
{
}
the catch (E)
{
the try
{
}
the catch (E)
{
Alert ( "your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.
{
//4代表请求已完成
if( xmlHttp.
{
document.myForm.time.value= xmlHttp.
}
}
xmlHttp.
xmlHttp.
}
</script>
<form name="myForm">
用户: <input type="text" name="username"
时间: <input type="text" name="time" />
</form>
</body>
</html> <%
This is the "time.asp" code:
-1 = Response.Expires // page is not cached
Response.Write (Time)
%>
<Script type = "text / JavaScript">
function the ajaxFunction ()
{
var
xmlHttp
;
the try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
the catch (E)
{
/ / Internet Explorer
the try
{
// IE 6.0+
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
the catch (E)
{
the try
{
// IE 5.5+
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
the catch (E)
{
Alert ( "your browser does not support AJAX!");
return false;
}
}
}
}
</ Script>
2. a simple Ajax application example
<HTML>
<body>
<Script type = "text / JavaScript">
function the ajaxFunction ()
{
var
xmlHttp
;
the try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
the catch (E)
{
// Internet Explorer
the try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
the catch (E)
{
the try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
the catch (E)
{
Alert ( "your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.
onreadystatechange
=function()
{
//4代表请求已完成
if( xmlHttp.
readyState
==4)
{
document.myForm.time.value= xmlHttp.
responseText
;
}
}
xmlHttp.
open("GET","time.asp",true)
;
xmlHttp.
send(null)
;
}
</script>
<form name="myForm">
用户: <input type="text" name="username"
onkeyup
="ajaxFunction();"
/>
时间: <input type="text" name="time" />
</form>
</body>
</html> <%
This is the "time.asp" code:
-1 = Response.Expires // page is not cached
Response.Write (Time)
%>
Reproduced in: https: //www.cnblogs.com/guoxiaowen/archive/2008/03/27/1125344.html