JS onbeforeunload Ajax使用

function send(){
  $.ajax({
    url: "url",
    async: true // 这里要用异步
  })
}

window.onbeforeunload(){
  send()
  return true;
}    

注意:Ajax中一定要用异步 否则下面的异常

"NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load '': Synchronous XHR in page dismissal. See https://www.chromestatus.com/feature/4664843055398912 for more details."

posted @ 2020-12-19 12:12  有间猫  阅读(462)  评论(0编辑  收藏  举报