title: window.onbeforeunload ajax request in Chrome
body: <p>I have a web page that handles remote control of a machine through Ajax. When user navigate away from the page, I'd like to automatically disconnect from the machine. So here is the code:</p>
  
  <pre><code>window.onbeforeunload = function () {
    bas_disconnect_only();
  }
  </code></pre>
  
  <p>The disconnection function simply send a HTTP GET request to a PHP server side script, which does the actual work of disconnecting:</p>
  
  <pre><code>function bas_disconnect_only () {
     var xhr = bas_send_request("req=10", function () {
     });
  }
  </code></pre>
  
  <p>This works fine in FireFox. But with Chrome, the ajax request is not sent at all. There is a unacceptable workaround: adding alert to the callback function:</p>
  
  <pre><code>function bas_disconnect_only () {
     var xhr = bas_send_request("req=10", function () {
       alert("You're been automatically disconnected.");
     });
  }
  </code></pre>
  
  <p>After adding the alert call, the request would be sent successfully. But as you can see, it's not really a work around at all.</p>
  
  <p>Could somebody tell me if this is achievable with Chrome? What I'm doing looks completely legit to me.</p>
  
  <p>Thanks,</p>