title: AJAX listener rather than polling?
body: <p>I created my own chat webserver in python and wanted to know instead of AJAX making a call to the server every second (JS below). I can modify my server so when ever it updates the chat.html file it pushes it out to all the clients. Is there a way using javascript to have it listen for any received data rather then polling?</p>
  
  <pre><code>&lt;script&gt;
  // Request the AJAX update the chat window every second
  setInterval(function(){loadChat()},1000);
  
  function loadChat()
  {
      var xmlhttp;
      if (window.XMLHttpRequest)
      {
          xmlhttp = new XMLHttpRequest();
  
          xmlhttp.onreadystatechange=function()
          {
              if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
              {
                  document.getElementById("chatWindow").innerHTML=xmlhttp.responseText;
              }
          }
  
          xmlhttp.open("GET","chat.html",true);
          xmlhttp.send(null);
      }
  }
  &lt;/script&gt;
  </code></pre>