handle ajax error when a user clicks refresh

后端 未结 5 1194
忘掉有多难
忘掉有多难 2020-12-02 17:17

i apologise if this is something i should be able to look up. all of the terms i wanted were way overloaded..

here is my problem: when i open a page, it fires off a

5条回答
  •  没有蜡笔的小新
    2020-12-02 17:34

    Combined version of nisanth074 and Peter V. Mørch answers, that worked for me.

    Example:

    var isPageBeingRefreshed = false;
    
    $(window).on('beforeunload', function(){
    
        isPageBeingRefreshed = true;
    });
    
    $.ajax({
    
        // Standart AJAX settings
    
    }).error(function(){
    
        if (!isPageBeingRefreshed) {
    
            // Displaying error message
        }
    });
    

提交回复
热议问题