jQuery ajax call in onunload handler firing AFTER getting the page on a manual refresh. How do I guarantee onunload happens first?

前端 未结 4 699
轮回少年
轮回少年 2021-01-20 02:37

I have a situation where on page unload I am firing a request to delete the draft of a user\'s work. This works fine until a user chooses to refresh the page, whereupon ins

4条回答
  •  死守一世寂寞
    2021-01-20 03:13

    In onbeforeunload or $.unload() set up your AJAX object with async = false. This will make sure the ajax call completes before the page is unloaded.

    I know this question is a few months old, but I wanted to add this info in case it helps anyone searching for a similar issue with AJAX!

提交回复
热议问题