Catching a JSONP error on a cross-domain request

前端 未结 4 1979
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 00:28

I\'m using jQuery.getJSON() on a URL (different domain) which may not exist. Is there a way for me to catch the error \"Failed to load resource\"? It seems that try/catch do

4条回答
  •  梦谈多话
    2021-01-13 00:38

    This works:

    j.ajaxSetup({
        "error":function(xhr, ajaxOptions, thrownError) {   
    
        console.log(thrownError);                           
    }});
    

提交回复
热议问题