Ajax.js
/**
* Ajax No refresh Two-level linkage pull-down menu (provinces and cities linkage)
*
* @author Arcow <arcow@126.com>
* @version 1.0
* @lastupdate 2005-12-29
*
*/
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) {//Judge 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) {//Judge 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) {//Judge 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
Send_request ("Select.server.php?action=province", 1);//service-side handler, Operation function
}
function loadcity () {//Download the market
document.getElementById ("District"). value= "";/Empty text box
Send_request ("select.server.php?action=city&id=" +document.getelementbyid ("province"). value,2);
}
function Inputdistrict () {//Enter selected provinces and cities into text boxes
Send_request ("select.server.php?action=district&id=" +document.getelementbyid ("province"). Value+ "&id1=" +document.getelementbyid ("City"). value,3);
}