title: Call ajax on before page unload
body: <p>I'm trying to call an ajax  before user leaving a page, this what i have done so far. But it doesn't even hit the ajax page.
  This is what i have done so far.  </p>
  
  <pre><code>window.onbeforeunload = closeIt();
  function closeIt()
  {
      var key="save-draft";
  
              $.ajax({
                  url: "app/ajax_handler.php",
                  type:"GET",
                  data:{key:key},
                  success: function(data)  {
                      return data;
                  }
              });
  
  }
  </code></pre>
  
  <p>I Have tried this one also both failed in my case.</p>
  
  <pre><code>$( window ).unload(function() {});
  </code></pre>