AjaxPHP brushless New Level 2 linkage drop-down menu (provincial/municipal linkage) source code _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.