title: receive multiple responses in javascript with one request
body: <p>How can I receive multiple responses from a server using javascript.</p>
  
  <p>I have a requirement where a request is posted one time with the data and number of iterations and at server side the request is processed for the number of iterations. On completion of each iteration the server sends back the response. So for one request and 10 iterations my java script need to receive the 10 responses and show it on the web page. Is there any way that I can handle this using javascript. I cannot use any other technology.</p>
  
  <p>Right now I am using the following way</p>
  
  <pre><code>    function showResponse(){
      xmlHttp = GetXmlHttpObject();
      var dataString = document.getElementById("request-parameters").value;
      var iterations = document.getElementById("iterations").value;
      if(xmlHttp==null){
          alert("your browser does not support AJAX!");
      }
      var url = "http://localhost:8080/servlet/requestServlet";
  
      xmlHttp.onreadystatechange=stateChanged;
      xmlHttp.open("POST",url,true);
      xmlHttp.send(dataString);
  }
  
  function GetXmlHttpObject(){
      var xmlHttp=null;
      try{
          //Firefox, Opera, Safari
          xmlHttp=new XMLHttpRequest();
      }catch(e){
          //IE
          try{
              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }catch(e){
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
      }
      return xmlHttp;
  }
  
  function stateChanged(){
      if(xmlHttp.readyState==4){
  
          if(xmlHttp.status == 200){
               var resp = xmlHttp.responseText;
               var responseDiv = document.getElementById("response");
              responseDiv.innerHTML=responseDiv.innerHTML+resp1[1];
  
              }
      }
  }
  </code></pre>
  
  <p>I cannot modify this approach. Is it possible to get it done with XmlHttp object.</p>