Window.onbeforeunload query execution

I try to execute an email request when a user leaves the page. The code I'm working with

<script type="text/javascript">
window.onbeforeunload = function(){
    var used = $('#identifier').val();
    $.post('conversation.php?leave=true',{ud:used});
}
</script>

Is there something wrong with what I'm doing here? The result that I get in the FF error console just says that other unrelated functions / variables are not defined (since they are unloaded). Any tips or pointers on what I need to fix?

+3
source share
1 answer

, AJAX beforeunload , , , , . , :

$.ajax({ 
  type: "POST", 
  url: 'conversation.php?leave=true', 
  data:{ud:used}, 
  async: false
});

, , , , , . , , async: false .

+5

Source: https://habr.com/ru/post/1776019/


All Articles