0

需要有关以下代码的帮助。问题是它只触发最后一个 xmlhttp.open 而不是两者。代码如下。

<script type="text/javascript">
function loadXMLDoc(obj){ 
  var xmlhttp; 
  var flag; 
  var mycode;
  mycode = obj;

  if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }else{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState==4 && xmlhttp.status==200){
    }
  }
   flag = document.getElementById(mycode);
   if (flag.value == "Uncall") {
     flag.value = "Call Patient";
     document.getElementById('myDiv'+mycode).innerHtml="<b><font color='#00FF00'>Called</font></b>";        
   }else{ 
     flag.value = "Uncall";
     document.getElementById('myDiv'+mycode).innerHtml="<b><font color='#00FF00'>Calling..</font></b>";
     **xmlhttp.open("GET","http://1.1.1.1/callnumber.cgi?"+mycode,true);
     xmlhttp.send();
     xmlhttp.open("GET","http://2.2.2.2/displaynumber.php?"+mycode,true);
     xmlhttp.send();**
   }
}
</script>

感谢一些意见

4

2 回答 2

2

不要重复使用相同的请求对象。

最好的建议是不要自己写这些。找到一个库并使用它们的实现。JQuery 还不错。还有很多其他选择。

于 2012-05-14T03:49:52.087 回答
0
<script type="text/javascript">
function loadXMLDoc(obj){
  var xmlhttp; 
  var flag;
  var mycode;
  mycode = obj;
  flag = document.getElementById(mycode);
  if (flag.value != "Uncall"){
      loadXMLDocCall(obj,"http://1.1.1.1/callnumber.cgi?");
      loadXMLDocCall(obj,"http://2.2.2.2/displaynumber.php?");
      flag.value = "Uncall";
      document.getElementById('myDiv'+mycode).innerHtml="<b><font color='#00FF00'>Calling..</font></b>";
      } else { 
       flag.value = "Call Patient";
       document.getElementById('myDiv'+mycode).innerHtml="<b><font color='#00FF00'>Called</font></b>";
      }
}
function loadXMLDocCall(obj,url){ 
  var xmlhttp; 
  var mycode;
  mycode = obj;

  if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }else{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState==4 && xmlhttp.status==200){
    }
  }
   xmlhttp.open("GET",url+mycode,true);
   xmlhttp.send();
 }
</script>
于 2012-05-14T03:57:46.873 回答