AjaxPHP node-less secondary linkage drop-down menu (provincial/municipal linkage) source code. Ajax. jsvarhttp_requestfalse; functionsend_request (url, method) {Initialize, specify the processing function, and send the request function http_requestfalse; start initializing XMLHttpRequest for ajax. js
Var http_request = false;
Function send_request (url, method) {// initialize, specify the processing function, and send the request function
Http_request = false;
// Start initializing the XMLHttpRequest object
If (window. XMLHttpRequest) {// Mozilla browser
Http_request = new XMLHttpRequest ();
If (http_request.overrideMimeType) {// sets the MiME category
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 ("the XMLHttpRequest object instance cannot be created .");
Return false;
}
Switch (method ){
Case 1: http_request.onreadystatechange = processRequest1; break; // select the operation function
Case 2: http_request.onreadystatechange = processRequest2; break;
Case 3: http_request.onreadystatechange = processRequest3; break;
}
// Determine the request sending method and URL and whether to execute the following code synchronously
Http_request.open ("GET", url, true );
Http_request.send (null );
}
// Function for processing the returned information
Function processRequest1 () {// operation function 1, transferred 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 () {// operation function 2, transferred to the city
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 ("city", 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 processRequest3 () {// operation function 3, input province/city
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 = "";
Document. getElementById ("district"). value = 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 loadProvince () {// load province
Http://www.bkjia.com/PHPjc/630419.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/630419.htmlTechArticleajax.js var http_request = false; function send_request (url, method) {// initialize, specify the handler, send the request function http_request = false; // start initializing XMLHttpRequest on...