title: Send AJAX to server beforeunload
body: <p><a href="https://stackoverflow.com/questions/5398772/firefox-4-onbeforeunload-custom-message">So supposedly starting at Firefox > 4</a>, binding the window jQuery object to <code>beforeunload</code> doesn't work anymore.</p>
  
  <p>What'd I'd like to do is submit an AJAX post to delete my server's memcache data.</p>
  
  <p>When I refresh the only open tab, I can see that the <code>beforeunload</code> event is called in both firefox and chrome with the following code as evidenced by the console.log message, "firefox/NON-firefox delete". The problem is that I never see the console.log message "memcache delete" indicating that my server never saw the <code>$.ajax</code> request.</p>
  
  <p>I realize it is bad to do browser sniffing and that there is no difference between what's included in the if and else statements. I'm merely showing code for what I've tried unsuccessfully in Firefox.</p>
  
  <p>Anyone have any ideas?</p>
  
  <pre><code>$(window).bind('beforeunload', function(){ 
    if(/Firefox[\/\s](\d+)/.test(navigator.userAgent) &amp;&amp; new Number(RegExp.$1) &gt;= 4) {
      console.log('firefox delete');
       memcacheDelete();
       return null;
    } 
    else {
      console.log('NON-firefox delete');
      memcacheDelete();
      return null;
    }
  });
  
  function memcacheDelete() {
     $.ajax({
        url: "/memcache/delete", 
        type: "post",
        data:{}, 
        success:function(){
            console.log('memcache deleted');
        }//success
    }); //ajax
  }
  </code></pre>