title: Detect Window Close with JQuery or Javascript AJAX request
body: <p>I want to get an Update about this topic.</p>
  
  <p>I find many posts here on how to use unload() and onbeforeunload events, but there are not working for me. I try putting inside and outside <code>$(document).ready(function(){}</code> but it is not resulting. I will show the post (5 years ago) where it lead me to create a new one. How should we use? Thank you!</p>
  
  <p><a href="https://stackoverflow.com/questions/18783535/jquery-beforeunload-when-closing-not-leaving-the-page">jquery beforeunload when closing (not leaving) the page?</a></p>
  
  <p>I try using without on, with onbeforeunload etc.</p>
  
  <p>Does not run the code inside the event. :S</p>
  
  <p>This is the code:</p>
  
  <pre><code>$(window).on("beforeunload", function () {
      return 'hi';
      $.ajax({
          type: 'POST',
          url: 'Cierre_unload.php',
          success: function () {
  
          }
      })
  })
  </code></pre>