ajax最基础应用
很厉害的异步操作,很神奇的效果,本来以为我是学不会了,结果还是会了,呵呵!凡是就怕琢磨啊!
第一步:创建Ajax实例
var xmlHttp;
function createxmlHttp(){
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
}
第二步:获取页面参数并执行对应程序
function CityAgent(CityID){ //由城市id得到该城市对应的代理商
createxmlHttp();
ItemCode=document.getElementById("FDItemCode_Chuan").value;
var URL="URL?FDItemCode_Chuan="+ItemCode+"";
xmlHttp.onreadystatechange=CityAgent_back;
xmlHttp.open("GET",URL,true);
xmlHttp.send(null);
}
第三步:把结果返回到对应页面中
function CityAgent_back(){ //返回由城市id得到该城市对应的代理商
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
document.getElementById("Agentid").innerHTML=xmlHttp.responseText;
}
}
else{
document.getElementById("Agentid").innerHTML="<img src=images/loading.gif>";
}
}