title: Sending empty request using XMLHttpRequest every 5 sec in JS return 304 in Internet Explorer 9
body: <p>I am writing a web app in java. In my html file I have a small javascript that sends an empty request to the server to preserve the session (HeartBeat) every five seconds. </p>
  
  <p>I am using a <code>XMLHttpRequest</code> Object to send the request to a <code>Tomcat</code> server.</p>
  
  <p>The problem is that in <code>IE9</code>, for the first request I get status <code>200</code> and after this, for every request I get <code>304</code> answer. In Firefox and Chrome it's working fine.</p>
  
  <p>How can I keep sending empty requests from my Javascript in IE and not getting 304.</p>
  
  <p>My code is:</p>
  
  <pre><code>&lt;script&gt;
  var HeartBeatTimer; 
  function StartHeartBeat(){
     // pulse every 30 seconds
      if (HeartBeatTimer == null)
        HeartBeatTimer = setInterval("HeartBeat()", 1000 * 5);
  }
  
  function HeartBeat(){
              var HTTP_Response = new XMLHttpRequest();
      HTTP_Response.open("GET", myurl , true);
      HTTP_Response.send(null);    
  }
  </code></pre>
  
  <p>   </p>
  
  <pre><code>my servlet that get the request:
  
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
          throws ServletException, IOException {
  </code></pre>
  
  <p>}</p>
  
  <p>The purpose of this script is to keep my session alive</p>