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

前端 未结 4 656
轮回少年
轮回少年 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:29

    I'm here to confirm @Silkster answer. I can fire an AJAX request after set an option async = false

    Here is the example code.

    $(window).unload( function () {
        $.ajaxSetup ({
            async: false  
        });
        $.get("target.php");
    });
    

提交回复
热议问题