title: Ajax (or JSONP) on unload with Safari/Chrome
body: <p>If you try to send an Ajax request, a JSONP request, or even a window.name request on unload, Safari and Chrome run the code, but the server never sees the request.  My theory is the thread of execution never allows the script tag to run before it changes the page.  Here is a test page with the JSONP test.  This code (and Ajax and window.name) creates a request for test.html in Firefox and IE7, but not Safari:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;script language="javascript" type="text/javascript"&gt;
              window.onunload = function(){
                  var encode = "UTF-8";
                  var script = document.createElement('script');
                  script.type = 'text/javascript';
                  script.src= "/test.html";
                  script.charset= encode;
                  document.body.appendChild(script)
              }
          &lt;/script&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Anyone know a good way to get around this?  More specifically, anyone know of a way to force Safari to send a request on unload?  The only solution I've found (which doesn't really help in my case) is synchronous XHR.</p>