Client:
Copy codeThe Code is as follows: <Head>
<Meta http-equiv = "Content-Type" content = "text/html"/>
<Script language = "javascript">
Var ajax;
Function createAjax ()
{
If (window. ActiveXObject)
{
Try
{
Return new ActiveXObject ("Msxm12.XMLHTTP ");
}
Catch (e)
{
Try
{
Return new
ActiveXObject ("Microsoft. XMLHTTP ");
}
Catch (e2)
{
Return null;
}
}
}
Else if (window. XMLHttpRequest)
{
Return new XMLHttpRequest ();
}
Else
{
Return null;
}
}
Function onRcvData ()
{
If (ajax. readyState = 4)
{
If (ajax. status = 200)
{
Var content = document. getElementById ('content ');
Content. innerHTML = ajax. responseText;
}
Else
{
Alert ("error ");
}
}
}
Function ajaxSendRequest (uri)
{
Ajax = createAjax ();
If (! Ajax)
{
Alert ("no ");
Return 0;
}
Ajax. onreadystatechange = onRcvData;
Ajax. open ("GET", uri, true );
Ajax. send ("");
}
</Script>
<Title> Hello AJAX </title>
</Head>
<Body>
<Div id = "content"> </div>
<Br>
<Input type = "button" value = "Hello"
Onclick = "ajaxSendRequest ('HTTP: // localhost: 8080/test/hello. jsp ')">
</Body>
</Html>
Server (hello. jsp)Copy codeThe Code is as follows: <Head>
<Title> hellp </title>
</Head>
<Body>
<%
Out. println ("hello ajax ");
%>
</Body>
</Html>