ajax简单应用

//获取ajax的xmlHttp
var xmlHttp = false;
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();
}

//ajax传参,在按钮事件中调用该方法
function changeurl(){

var bankname  = document.getElementById("bankname").value;
var repaymount  = document.getElementById("repaymount").value;
var url="cxfresponse.asp?bankname="+bankname+"&repaymount="+repaymount+"&m="+Math.random();
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=getresult;
xmlHttp.send(null);




}

//ajax接收数据
function getresult(){
if(xmlHttp.readyState == 4){
var responseword = xmlHttp.responseText;

var word=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="";
}


}

}

你可能感兴趣的:(Ajax,ajax简单应用)