handle ajax error when a user clicks refresh

后端 未结 5 1185
忘掉有多难
忘掉有多难 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:47

    The above techniques does not work for a periodically refreshing page (for example every half seconds). I have figured out that the error caused by refreshing the page can be avoided using delaying the error handling process by a small amount of time.

    Example:

    $.ajax(...)
    .success(...)
    .error(function(jqXHR) {
    setTimeout(function() {
      // error showing process
    }, 1000);
    });
    

    In addition to that

    window.onbeforeunload = function() {//stop ajax calls}

    event can be used for less frequently refreshing ajax calls.

提交回复
热议问题