ajax 报类型不匹配
function selectBig(large) {
if(large != "请选择") {
var xmlHttp = createXmlHttp();
var url ="/sport/ProductServlet?task=selectBig&bigName="+large+"&date="+new Date();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=
handleStateChange(xmlHttp); xmlHttp.send();
}
}
function handleStateChange(xmlHttp) {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
var xml = xmlHttp.responseXML;
var types = xml.getElementsByTagName("type");
var child = document.getElementById("child");
document.getElementById("child").options.length= 1;
for(var i=0;i<types.length;i++) {
var name = types[i].childNodes[0].text;
var value = types[i].childNodes[1].text;
var child = document.getElementById("child");
child.options.add(new Option(name,value));
}
}
}else {
alert("ajax出错");
}
}
function createXmlHttp()
{ var xmlHttp;
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
}
解决办法:
xmlHttp.onreadystatechange = function(){//此处检测状态,知道符合要求时,才会执行事件
if(xmlHttp.readyState==4 && xmlHttp.status == 200){
handleStateChange(xmlHttp);
}