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

前端 未结 3 1985
天涯浪人
天涯浪人 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条回答
  •  猫巷女王i
    2020-12-15 04:24

    Checking the status didn't work for me, but

    // Ignore incomplete requests, likely due to navigating away from the page
    if (jqXHR.readyState < 4) {
        return true;
    } 
    

    in the error handler did (4 being DONE).

提交回复
热议问题