javascript - Jquery - Post beforeunload -


i want post data before unload (just before visitor closes page). unload may vary on different browsers, have done following script;

$(document).ready(function(){  var runme = true;  $(window).bind('beforeunload', function () {     if(runme){  if ($("#benyaziyormuyum").val()=="evet") {  $.post("yazmabirak.php", { karsidaki: "exited", });  }         runme=false;     }  });  $(window).unload(function () {     if(runme){  $.post("yazmabirak.php", { karsidaki: "exited", });         runme=false;     } }); 

it works on browsers, except chrome. question is, before unload function should used make work on chrome ?

are sure isn't getting called?

$.post asynchronous call , have nothing prevents browser continuing on after $.post().

you need make synchronous using $.ajax() can set async: false

how make jquery "$.post" request synchronous

http://api.jquery.com/jquery.ajax/


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -