Error handling in getJSON calls

后端 未结 9 1634
野的像风
野的像风 2020-11-28 02:09

How can you handle errors in a getJSON call? Im trying to reference a cross-domain script service using jsonp, how do you register an error method?

9条回答
  •  情深已故
    2020-11-28 02:41

    In some cases, you may run into a problem of synchronization with this method. I wrote the callback call inside a setTimeout function, and it worked synchronously just fine =)

    E.G:

    function obterJson(callback) {
    
    
        jqxhr = $.getJSON(window.location.href + "js/data.json", function(data) {
    
        setTimeout(function(){
            callback(data);
        },0);
    }
    

提交回复
热议问题