0

Can you tell me why this doesn't work..?? also tried with window.unload but it also didn't worked

   window.onbeforeunload = function(){ 
                 $.ajax({
             url:'logout.php',
             type:'POST',
             data:{user:$("#user").val()},
             success: function(response){

                   alert(response);
                 }


             })      

}
Asce4s
  • 819
  • 3
  • 10
  • 16

2 Answers2

0

Well, you can set async: false on your AJAX call to make the browser wait for the request to finish before doing anything else, but note that this will 'hang' the browser for the duration of the request.

async: false,

Ashwin Parmar
  • 3,025
  • 3
  • 26
  • 42
0

Make the ajax call synchronous. As the call is asynchronous, before you get anything back the window is closed.

bhb
  • 2,476
  • 3
  • 17
  • 32