getJSON timeout handling

后端 未结 6 1079
抹茶落季
抹茶落季 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:05

    the setTimeout function executes a set of code after a specified number of milisecons in the global scope.

    The getJSON function (per the jQuery documentation here http://api.jquery.com/jQuery.getJSON/) is shorthand for:

    $.ajax({
      dataType: "json",
      url: url,
      data: data,
      success: success
    });
    

    so you would want to make your call like so:

    $.ajax({
      dataType: "json",
      url: url,
      data: data,
      success: success,
      timeout: 15000
    });
    
    $('.loadingDiv')
        .hide()
        .ajaxStart(function() {
            $(this).fadeIn();
        })
        .ajaxStop(function() {
            $(this).fadeOut();
        });
    

提交回复
热议问题