title: how to send a value to the server using ajax object after getting response send another value on a separate line using the same object
body: <p>hi i'm new to ajax and javascript and i'm experiencing a a bit of a problem with
  sending requests to the server.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>function process(){
   if(xmlHttp.readyState==0 || xmlHttp.readyState==4){
     Selected_word = document.getSelection();
     xmlHttp.open("GET","/gwizz/scripts/definition.php?word="+Selected_word,true);
     xmlHttp.onreadystatechange = handleServerResponse;
     xmlHttp.send(null);
  
   }else{
      setTimeout('process()',1000);
   }
  }
  </code></pre>
  
  <p>i am using the function "process()" to send request to server when a double click lister is triggered on the document body. The response that i get from the server is an xml file and its content is displayed on a jquery pop-up modal as you can see in the "handleServerResponse()" function below. </p>
  
  <p>My problem is that i want to send another request to the server after the pop-up modal is closed. I've tried doing this by using the open and send properties of my xmlHttp object and sending a request to a different php script right under the onClose() frunction of the pop-up modal. but its not sending those value to the php script.</p>
  
  <p>How can i use this signle ajax object to send values to the server at diffrent stages of my code?. Any help will be appriciated. Thanks.</p>
  
  <pre><code>function handleServerResponse(){
    if(xmlHttp.readyState==4){
       if(xmlHttp.status==200){   
          var xmlResponse = xmlHttp.responseXML;
          var xmlDocumentElement = xmlResponse.documentElement;
          Definition = xmlDocumentElement.firstChild.data;
   $('#element_to_pop_up').bPopup({       
                  onOpen:function(){
                          modal_open = time();                        
                             document.getElementById("element_to_pop_up").innerHTML = "&lt;span style='font-weight: bold;font-size: 25pt'&gt;"+ Selected_word;
  
                  },
                  onClose:function(){
                          modal_close = time();
                          document.getElementById("element_to_pop_up").innerHTML = "";
                          username = "beach";
                          xmlHttp.open("GET","/gwizz/scripts/logfile.php?word="+Selected_word + "&amp;username=" + username + "&amp;modal_close=" + modal_close + "&amp;modal_open=" + modal_open,true);
                          xmlHttp.send(null);                 
                  }               
          });
       }else{
          alert('Something went wrong with process!!!');  
      }
  }
  </code></pre>
  
  <p>}</p>