Problem submitting form on window.unload

后端 未结 2 1831
耶瑟儿~
耶瑟儿~ 2021-01-16 10:03

I am having a problem submitting form on window unload if form information has been updated (album.updated = true):

window.onunload = function(evnt) {
  if (album         


        
2条回答
  •  情深已故
    2021-01-16 10:50

    You cannot reliably interact with the server from the unload event.

    Sending an AJAX request might be a little more reliable, but should also not be relied on.

    Instead, you should handle the onbeforeunload event and return "You have unsaved changes";.
    This will instruct the browser to show a confirmation dialog allowing the user to cancel the navigation. (After which he can save manually)

提交回复
热议问题