//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;
}
}