Method 1:
<Script language = "JavaScript">
VaR xmlttp;
Function verify (){
// Obtain the text value in Dom Mode
VaR username = Document. getelementbyid ("username"). value;
// You need to create this object for IE and other browsers to write different code in different ways
If (window. XMLHttpRequest ){
// For IE7, 8, Firefox, opera, and mozillar
XMLHTTP = new XMLHttpRequest ();
// Fix bugs of javasillar in certain versions
If (XMLHTTP. overridemimetype ){
XMLHTTP. overridemimetype ("text/html ");
}
} Else if (window. activexobject ){
// For IE6, ie5.5, and ie5
// Two control names that can be used to create the XMLHTTPRequest object are saved in a JS array.
// Prefix the newer version
VaR activexname = ["msxml2.xmlhttp", "Microsoft. XMLHTTP"];
For (VAR I = 0; I <activexname. length; I ++ ){
Try {
// Take a control to create it. If it is successful, it will finally Loop
// If the creation fails, an exception is thrown, and the execution continues.
XMLHTTP = new activexobject (activexname [I]);
Break;
} Catch (e ){}
}
}
// Determine whether XMLHttpRequest is successfully created
If (! XMLHTTP ){
Alert ("XMLHTTPRequest object creation failed ");
} Else {
Alert (XMLHTTP );
}
// Register the callback function
XMLHTTP. onreadystatechange = callback;
// The first parameter sets the request method, get and post
// Set the URL of the second parameter
// The third parameter, "true", indicates synchronous interaction, and "false" indicates Asynchronous interaction.
XMLHTTP. Open ("get", "Servlet/testservlet? Username = "+ username, true );
// Send data
// In synchronous mode, send is executed only after the server data is returned.
// In asynchronous mode, send is executed immediately
XMLHTTP. Send (null );
}
Function callback (){
// Receives response data
// Determine whether the interaction is complete
If (4 = XMLHTTP. readystate ){
// Determine whether the interaction is successful
If (200 = XMLHTTP. Status ){
// Obtain the data returned by the server
// Obtain the plain text data output by the server
VaR responsetext = XMLHTTP. responsetext;
VaR divnode = Document. getelementbyid ("result ");
Divnode. innerhtml = responsetext;
}
}
}
</SCRIPT>
The second method is implemented using jquery.
<SCRIPT type = "text/JavaScript" src = "JS/jquery-1.3.min.js"> </SCRIPT>
<Script language = "JavaScript">
Function verify (){
$. Get ("Servlet/testservlet? Username = "+ $ (" # username "). Val (), null, function (data ){
$ ("# Result" pai.html (data );
});
}
</SCRIPT>
Jquery may be much more convenient, but the principle should still be understood. Otherwise, it would be too big to change the framework!