How to handle jQuery ajax post error when navigating away from a page

前端 未结 3 1983
天涯浪人
天涯浪人 2020-12-15 03:27

Is there a way to handle the error from an ajax request within JQuery such that when the user navigates away from the page, the resulting error is ignored?

$         


        
3条回答
  •  情话喂你
    2020-12-15 04:32

    I've had to handle this issue too a couple of times.

    I'd recommend binding to the $(window).unload event, setting some variable somewhere, such as in your namespace (App.unloading = true) and then testing it in ajax error callbacks.

    See http://api.jquery.com/unload/

提交回复
热议问题