javascript - AJAX Unload not firing -
i need run process when user exists or leaves page. have following code received question posted:
<script> var unloaded = false; $(window).on('beforeunload', unload); $(window).on('unload', unload); function unload() { if (!unloaded) { $.ajax({ type: 'post', async: false, url: '/function/left/@viewbag.id', success: function () { unloaded = true; $('body').css('cursor', 'default'); }, timeout: 5000 }); } }
the problem /function/left event never fired. wrong?
Comments
Post a Comment