Basic Ajax writing
<Script language = "JavaScript" type = "text/JavaScript">
// Create XMLHttpRequest
Function createxmlgttprequest (){
If (window. activexobject) {// IE browser
Return new activexobject ("Microsoft. XMLHTTP ");
} Else if (window. XMLHttpRequest) {// non-IE browser
Return new XMLHttpRequest ();
}
}
// send the request
var XMLHttpRequest; // declare the XMLHTTPRequest object
function tosendrequest () {
XMLHttpRequest = createxmlgttprequest ();
XMLHttpRequest. onreadystatechange = callbackfun; // sets the callback function. When the status of the XMLHTTPRequest object changes, call the callbackfun function.
// initializes the XMLHttpRequest component; the third parameter indicates synchronous (false) or asynchronous (true ), asynchronous means that after calling the send method to send a request, you do not have to wait for the request response to continue executing the following JavaScript Code .
XMLHttpRequest. Open ("get", "Ajax. ashx? Name = name1 & pass = pass1 ", true);
XMLHttpRequest. Send (null); // send a request
}
// callback function
function callbackfun () {
// readystate is in 5 states, 0 is not initialized, 1 is initialized, 2 is sent, 3. Receive the result. 4. The result is received.
// status server response status code.
If (XMLHttpRequest. readystate = 4 & XMLHttpRequest. status = 200) {
alert (XMLHttpRequest. responsetext);
}else {
// exception
}< BR >}< br>