getJSON timeout handling

后端 未结 6 904
借酒劲吻你
借酒劲吻你 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:15

    I don't think any of these answers are ideal. I know this is years late, but what you want to do is use the success/error callback options of the .ajax(); method when receiving a JSONP response.

    Example of how I would structure this:

        // Call
        $.ajax({
    
          // URL you want to get
          url: 'http://example.com/json?callback=?',
    
          // Set a realistic time in milliseconds
          timeout: 3000,
    
          // Put in success callback function here, this example
          // shows you the data you got back from the call
          success: function(data) {
            console.log(data);
          },
    
          // Put in an error handling function, just an alert in this case
          error: function(badData) {
            alert('The call was unsuccessful');
          },
    
          type: 'POST'
        });
    

提交回复
热议问题