-1

On Chrome its working properly but on firefox its not working

function myfoo(){
         // Write your logic here
           $.ajax({
            type: "POST",
            url: "update.php",
            dataType: 'json',
             data: {Eventid: 'Eventid',Seats:'Seats'},
            success: function (r) {}

});
    }

When unloading window

$(window).on('beforeunload', function () {
   return 'Are you sure you want to leave?';
});

when unloading call function

$(window).on('unload', function () {
   console.log('calling ajax');
   myfoo();
});
Jelmergu
  • 973
  • 1
  • 7
  • 19
Rony
  • 3
  • 4
  • Possible duplicate of [Why is jQuery onbeforeunload not working in Chrome and Firefox?](https://stackoverflow.com/questions/22776544/why-is-jquery-onbeforeunload-not-working-in-chrome-and-firefox) – Justinas May 24 '17 at 06:04
  • it is working. it just isn't doing what you'd hope it does. this behavior is well documented. – Kevin B May 24 '17 at 06:10
  • can you help me in this code? – Rony May 24 '17 at 06:12
  • in chrome this code running perfectly, but in firefox it it does not updating records on window close. like in chrome it is do – Rony May 24 '17 at 06:15

1 Answers1

1

Both "onbeforeunload" and "unload" is working but in your scenario you are expecting to send ajax call. so try changing ajax asynchronous to false.

function myfoo(){
         // Write your logic here
           $.ajax({
            type: "POST",
            url: "update.php",
            dataType: 'json',
            async: false,
             data: {Eventid: 'Eventid',Seats:'Seats'},
            success: function (r) {}

});
    }
ram vinoth
  • 472
  • 4
  • 14