+ -
当前位置:首页 → 问答吧 → 高分求助~帮忙看下这个ajax怎么复制一份

高分求助~帮忙看下这个ajax怎么复制一份

时间:2011-11-01

来源:互联网

<body onLoad="callServer();callServer1()">
<!--略 -->
 <select name="plantname" id="plantname" onchange="callServer()">

<!--略 -->
<select name="employeename" id="employeename" onchange="callServer1()" >

</body>

我这样写为什么不对?

<script>

/* 第一份 */
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();
}

function callServer() {
  var name = document.getElementById("plantname").value;
  if ((name == null) || (name == "")) return;
  var url = "loadingdeptname.asp?pl_id=" + escape(name);
  xmlHttp.open("GET", url, true);
  xmlHttp.onreadystatechange = updatePage;
  xmlHttp.send(null);  
}



function updatePage() {
  if (xmlHttp.readyState < 4) {
 depta.innerHTML="正加載部門數據......";
  }
  if (xmlHttp.readyState == 4) {
  var response = xmlHttp.responseText;
 depta.innerHTML=response;
  }
}




/* 第二份 */

var xmlHttp1 = false;
try {
  xmlHttp1 = new ActiveXObject1("Msxml2.xmlHttp1");
} catch (e) {
  try {
  xmlHttp1 = new ActiveXObject1("Microsoft.xmlHttp1");
  } catch (e2) {
  xmlHttp1 = false;
  }
}
if (!xmlHttp1 && typeof xmlHttp1Request1 != 'undefined') {
  xmlHttp1 = new xmlHttp1Request1();
}

function callServer1() {
  var name1 = document.getElementById("employeename").value;
  if ((name1 == null) || (name1 == "")) return;
  var url1 = "loadingemployeename.asp?d_id=" + escape(name);
  xmlHttp1.open("GET", url1, true);
  xmlHttp1.onreadystatechange1 = updatePage1;
  xmlHttp1.send(null);  
}

function updatePage1() {
  if (xmlHttp1.readyState1 < 4) {
 employeen.innerHTML="正加載部門數據......";
  }
  if (xmlHttp1.readyState1 == 4) {
  var response1 = xmlHttp1.responseText;
 employeen.innerHTML=response;
  }
}
</script>

作者: shugeer   发布时间: 2011-11-01

你可以

  if (xmlHttp.readyState == 4) {
if(xmlHttp.status==200)
{
  var response = xmlHttp.responseText;
 document.getElementById("depta").innerHTML=response;
}
  }
else
{
 document.getElementById("depta").innerHTML="正加載部門數據......";
}

作者: net_lover   发布时间: 2011-11-01

热门下载

更多