Ajax. js/*** ajax brushless New Level 2 linkage drop-down menu (provincial/municipal linkage) ** @ authorarcowarcow@126.com * @ version1.0 * @ lastupdate2005-12-29 **/varhttp_request = false; functionsend_request
Ajax. js
/**
* Ajax No-refreshing secondary linkage drop-down menu (provincial/municipal linkage)
*
* @ Author arcow <Arcow@126.com>
* @ Version 1.0
* @ Lastupdate 2005-12-29
*
*/
Var http_request = false;
Function send_request (url, method) {// initialize, specify the processing function, and send the request function
Http_request = false;
// Initialize the XMLHttpRequest object
If (window. XMLHttpRequest) {// Mozilla browser
Http_request = new XMLHttpRequest ();
If (http_request.overrideMimeType) {// Set the MiME type
Http_request.overrideMimeType ('text/XML ');
}
}
Else if (window. ActiveXObject) {// IE browser
Try {
Http_request = new ActiveXObject ('msxml2. xmlhttp ');
} Catch (e ){
Try {
Http_request = new ActiveXObject ('Microsoft. xmlhttp ');
} Catch (e ){}
}
}
If (! Http_request) {// exception. An error occurred while creating the object instance.
Window. alert ('cannot create XMLHttpRequest object instance .');
Return false;
}
Switch (method ){
Case 1: http_request.onreadystatechange = processRequest1; break; // select the control function
Case 2: http_request.onreadystatechange = processRequest2; break;
Case 3: http_request.onreadystatechange = processRequest3; break;
}
// Determine the method and URL for sending the request and whether to synchronously execute the following code
Http_request.open ('GET', url, true );
Http_request.send (null );
}
// Function for processing the returned information
Function processRequest1 () {// controls function 1 and transfers it to the province
If (http_request.readyState = 4) {// identifies the object status
If (http_request.status = 200) {// The information has been returned successfully. start to process the information.
Document. getElementById ('statustxt '). innerHTML = '';
AddOptionGroup ('Province ', http_request.responseText );
} Else {// The page is abnormal.
Alert ('The page you requested has an exception. ');
}
} Else {// as long as the read is not completed
Document. getElementById ('statustxt '). innerHTML = 'regular reading ...... ';
}
}
Function processRequest2 () {// controls function 2 and transfers it to the city.
If (http_request.readyState = 4) {// identifies the object status