Client section:
Copy Code code as follows:
<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>
<body>
<div id= "Content" ></div>
<br>
<input type= "button" value= "Hello"
onclick= "Ajaxsendrequest (' http://localhost:8080/test/hello.jsp ')" >
</body>
Server-side section (hello.jsp)
Copy Code code as follows:
<title>hellp</title>
<body>
<%
Out.println ("HELLO AJAX");
%>
</body>