getJSON timeout handling

后端 未结 6 1000
借酒劲吻你
借酒劲吻你 2021-02-12 10:36

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 10:59

    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.

提交回复
热议问题