getJSON timeout handling

后端 未结 6 1097
抹茶落季
抹茶落季 2021-02-12 10:25

I am using jQuery getJSON() function. This function getting data with no problem. But sometimes waiting, waiting waiting... And my loading bar showing loading loadi

6条回答
  •  伪装坚强ぢ
    2021-02-12 11:21

    getJSON() returns a promise on which you can call the abort function :

    var p = $.getJSON(..., function(){ alert('success');});
    setTimeout(function(){ p.abort(); }, 2000);
    

    EDIT : but if your goal is just to abort if it takes too much time, then lethal-guitar's answer is better.

提交回复
热议问题