ajax简单应用
//获取ajax的xmlHttp
varxmlHttp=false;
try{
xmlHttp=newActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=newActiveXObject("Microsoft.XMLHTTP");
}catch(e2){
xmlHttp=false;
}
}
if(!xmlHttp&&typeofXMLHttpRequest!='undefined'){
xmlHttp=newXMLHttpRequest();
}
//ajax传参,在按钮事件中调用该方法
functionchangeurl(){
varbankname=document.getElementById("bankname").value;
varrepaymount=document.getElementById("repaymount").value;
varurl="cxfresponse.asp?bankname="+bankname+"&repaymount="+repaymount+"&m="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=getresult;
xmlHttp.send(null);
}
//ajax接收数据
functiongetresult(){
if(xmlHttp.readyState==4){
varresponseword=xmlHttp.responseText;
varword=responseword.split("+");
document.getElementById("repaymount").value=word[0];
document.getElementById("cxf").value=word[1];
document.getElementById("str").innerHTML=word[2];
if(word[2]==""){
document.getElementById("tishi").style.display="none";
}else{
document.getElementById("tishi").style.display="";
}
}
}