//AJAX request for the city data
function ajaxforget(cn) {
var xmlhttp_request = "";
try {
if (window.ActiveXObject) {
for (var i = 5; i; i--) {
try {
if (i == 2) {
xmlhttp_request = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
xmlhttp_request = new ActiveXObject("Msxml2.XMLHTTP." + i + ".0");
}
break;
}
catch (e) {
xmlhttp_request = false;
}
}
}
else if (window.XMLHttpRequest) {
xmlhttp_request = new XMLHttpRequest();
}
}
catch (e) { xmlhttp_request = false; }
if (!xmlhttp_request) {
alert("您的浏览器不支持ajax");
return;
}
xmlhttp_request.open('GET', '../Handler/CityData.ashx?code='+cn+'&time='+new Date().getMilliseconds(), true);
xmlhttp_request.setRequestHeader("Content-Type", "text/xml"); //setRequestHeader("header", "value")
xmlhttp_request.setRequestHeader("Charset", "gb2312"); //把指定首部设置为所提供的值。在设置任何首部之前必须先调用open()
xmlhttp_request.send(null);
var self = xmlhttp_request; //把引用赋给临时变量self
xmlhttp_request.onreadystatechange = function() {
thecallback(self);
};
}
//ajax的回调函数
function thecallback(xmlhttp_request) {
if (xmlhttp_request.readyState == 4 && xmlhttp_request.status == 200) {
//绑定项
var data = xmlhttp_request.responseXML;
var citys = data.getElementsByTagName("name");
var cns = data.getElementsByTagName("code");
var listCity = $("listCity");
listCity.innerHTML = ""; //先移除所有的项
var listP = $("listProvince");
var code = listP.options[listP.selectedIndex].value;
var item = new Array();
for (var i = 0; i < citys.length; i++) {
if (citys.length != 1 && code == cns[i].childNodes[0].data) continue;
item[i] = document.createElement("option");
item[i].value = cns[i].childNodes[0].data;
item[i].innerHTML = citys[i].childNodes[0].data;
listCity.appendChild(item[i]);
}
//绑定项结束
$("txtCode").value = listCity.options[0].value;
}
}