我需要以jQuery.ajax调用的形式重新格式化下面的函数,以便进行错误处理(脚本显然在某些调用上超时)。如果使用错误回调和成功回调转换为.ajax(),这会是什么样子?
jQuery.getJSON("http://boss.yahooapis.com/ysearch/web/v1/tobacco"
+"appid=myAppID"
+"&lang=en"
+"&format=json"
+"&count=50"
+"&view=keyterms"
+"&callback=?",
function (data) {
// if no error, do something, else gracefully exit
});
答案 0 :(得分:2)
$.ajax({ url: "http://boss.yahooapis.com/ysearch/web/v1/tobacco"
+"appid=myAppID"
+"&lang=en"
+"&format=json"
+"&count=50"
+"&view=keyterms"
+"&callback=?",
success: function(data){
//do somethign with the data
},
error:function(XMLHttpRequest, textStatus, errorThrown){
//do something on error
}
});
答案 1 :(得分:0)
我知道这是5年之后,但你可能不应该构建自己的查询字符串
$.ajax({ url: "http://boss.yahooapis.com/ysearch/web/v1/tobacco",
data: {appid: "myAppID",
lang: "en",
format: "json",
count: "50",
view: "keyterms",
callback: "?"},
type: "GET",
dataformat: "JSON",
success: function(data){
//do something with the data
},
error:function(XMLHttpRequest, textStatus, errorThrown){
//do something on error
}
});