Ajax PHP No refresh two-level linkage drop-down menu (provinces and cities linkage) source code

Source: Internet
Author: User

Ajax.js

var http_request = false;
function Send_request (Url,method) {//initialization, specifying handler functions, sending requests
Http_request = false;
Start initializing the XMLHttpRequest object
if (window. XMLHttpRequest) {//mozilla browser
Http_request = new XMLHttpRequest ();
if (http_request.overridemimetype) {//Set 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, failed to create object instance
Window.alert ("Cannot create XMLHttpRequest object instance.");
return false;
}
Switch (method) {
Case 1:http_request.onreadystatechange = processrequest1;break;//Select Action function
Case 2:http_request.onreadystatechange = Processrequest2;break;
Case 3:http_request.onreadystatechange = Processrequest3;break;
}
Determine how and when the request is sent and whether the next code is executed synchronously
Http_request.open ("Get", url, True);
Http_request.send (NULL);
}
Functions that process return information
function ProcessRequest1 () {//Operation functions 1, transfer to province
if (http_request.readystate = = 4) {//Decision object state
if (Http_request.status = = 200) {//information has been successfully returned to start processing information
document.getElementById ("Statustxt"). innerhtml= "";
Addoptiongroup ("province", Http_request.responsetext);
} else {//page is not normal
Alert ("The page you are requesting has an exception.) ");
}
}else {///As long as not read complete
document.getElementById ("Statustxt"). Innerhtml= "Regular reading of data ...";
}
}

function ProcessRequest2 () {//Operation functions 2, transfer into the market
if (http_request.readystate = = 4) {//Decision object state
if (Http_request.status = = 200) {//information has been successfully returned to start processing information
document.getElementById ("Statustxt"). innerhtml= "";
Addoptiongroup ("City", Http_request.responsetext);
} else {//page is not normal
Alert ("The page you are requesting has an exception.) ");
}
}else {///As long as not read complete
document.getElementById ("Statustxt"). Innerhtml= "Regular reading of data ...";
}
}

function ProcessRequest3 () {//Operation functions 3, input Provinces
if (http_request.readystate = = 4) {//Decision object state
if (Http_request.status = = 200) {//information has been successfully returned to start processing information
document.getElementById ("Statustxt"). innerhtml= "";
document.getElementById ("District"). Value=http_request.responsetext;
} else {//page is not normal
Alert ("The page you are requesting has an exception.) ");
}
}else {///As long as not read complete
document.getElementById ("Statustxt"). Innerhtml= "Regular reading of data ...";
}
}

function Loadprovince () {//loading into the province

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.