Home  >  Article  >  Backend Development  >  Ajax PHP no refresh secondary linkage drop-down menu (province and city linkage) source code_PHP tutorial

Ajax PHP no refresh secondary linkage drop-down menu (province and city linkage) source code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:07:211513browse

ajax.js

var http_request = false;
function send_request(url,method) {//Initialization, designated processing function, function to send request
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
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 operation function
case 2: http_request.onreadystatechange = processRequest2;break;
case 3: http_request.onreadystatechange = processRequest3;break;
}
// Determine the method and URL of sending the request and whether to execute the next code synchronously
http_request.open("GET", url, true);
http_request.send(null);
}
// Function to process returned information
function processRequest1() {//Operating function 1, transfer into province
if (http_request.readyState == 4) { // Determine object status
if (http_request.status == 200) { // The information has been returned successfully, start processing the information
document.getElementById("statusTxt").innerHTML="";
addOptionGroup("province",http_request.responseText);
} else { //The page is abnormal
alert("There is an exception in the page you requested.");
}
}else {//As long as the reading is not completed
document.getElementById("statusTxt").innerHTML="Regular reading data...";
}
}

function processRequest2() {//Operating function 2, transfer into the market
if (http_request.readyState == 4) { // Determine object status
if (http_request.status == 200) { // The information has been returned successfully, start processing the information
document.getElementById("statusTxt").innerHTML="";
addOptionGroup("city",http_request.responseText);
} else { //The page is abnormal
alert("There is an exception in the page you requested.");
}
}else {//As long as the reading is not completed
document.getElementById("statusTxt").innerHTML="Regular reading data...";
}
}

function processRequest3() {//Operation function 3, enter province and city
if (http_request.readyState == 4) { // Determine object status
if (http_request.status == 200) { // The information has been returned successfully, start processing the information
document.getElementById("statusTxt").innerHTML="";
document.getElementById("district").value=http_request.responseText;
} else { //The page is abnormal
alert("There is an exception in the page you requested.");
}
}else {//As long as the reading is not completed
document.getElementById("statusTxt").innerHTML="Regular reading data...";
}
}

function loadProvince() {//Load province

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630419.htmlTechArticleajax.js var http_request = false; function send_request(url,method) {//Initialization, specify processing function, The function that sends the request http_request = false; //Start initializing the XMLHttpRequest pair...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn