getJSON timeout handling

后端 未结 6 909
借酒劲吻你
借酒劲吻你 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 11:01

    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();
        });
    

提交回复
热议问题