【发布时间】:2014-12-14 23:00:40
【问题描述】:
我的尝试中有一个$.getJSON() 调用,它抛出了一个错误,但没有触发捕获。什么都没有发生。只是控制台中的错误。
这是为什么?
如果 JSON 已加载,我要做的是做一些事情,如果请求中出现失败或错误,则做其他事情。
这是我的代码:
try{
$.getJSON('https://www.googleapis.com/freebase/v1/search?query=&filter=(all+type%3A%22nominated%20works+exhibited_at%3A%222012%20grammy%27s%22)&indent=true', function(searchJSON){
alert('sucesss!');
});
}
catch(e){
alert('failure: '+e);
}
这是一个 jsfiddle 的链接:http://jsfiddle.net/sgeg56c3/
【问题讨论】:
标签: javascript jquery json try-catch