javascriptgm-xmlhttprequest

get 2 different url using xmlhttp.open


Need help on this following code. the problem is it only trigger the last xmlhttp.open not both. code as below.

<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>

appreciate some input


Solution

  • <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>