How to execute ajax function onbeforeunload?

Solution 1:

You fire your ajax async (default for jquery - ajax). But the browser won't wait for anything on unload.

try setting async : false in the ajax-settings. But you can never be sure that this will work in all browsers everytime.

see the comment here: http://api.jquery.com/unload/#dsq-comment-body-132164390