var xmlHttp;
function getxml(){
if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
if (xmlHttp.overrideMimeType) {
xmlHttp.overrideMimeType("text/xml");
}
}
else if (window.ActiveXObject) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!xmlHttp) {
window.alert("can't create XMLHttpRequest object.");
return null;
}
return xmlHttp;
}
function getModel(){
xmlHttp=getxml();
var makeName = document.getElementById("makeName").value;
var yearName = document.getElementById("yearName").value;
var url = "<%=request.getContextPath()%>/website/index.do?method=getModel&makeName="+makeName+"&yearName="+yearName;
xmlHttp.open("POST",url,false);
xmlHttp.send(null);
xmlHttp.onreadystatechange = callback();
}
function callback(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
getModelResponse();
xmlHttp = null;
}
}
}
function getModelResponse(){
clearModelList();
var modelNames = xmlHttp.responseXML.getElementsByTagName("modelName");
var dlcModel = document.getElementById("modelName");
var option = null;
for(var i=0;i<modelNames.length;i++){
option = document.createElement("option");
option.appendChild(document.createTextNode(modelNames[i].firstChild.nodeValue));
option.value = modelNames[i].firstChild.nodeValue;
dlcModel.appendChild(option);
}
}
function clearModelList(){
var model = document.getElementById("modelName");
while(model.childNodes.length>0){
model.options.length = 0
}
}
ajax 回调 多浏览器
最新推荐文章于 2023-11-07 00:43:27 发布