[英]Freebase: javascript, how to know the status response
I think it's supposed to be on the response.code property, but I inspect the response object in firebug and I don't find the status response code anywhere. 我认为它应该在response.code属性上,但是我在萤火虫中检查了响应对象,但是在任何地方都找不到状态响应代码。 How do I know if the response is succesfull?
我如何知道响应是否成功? Thanks.
谢谢。
In newer versions (1.5+) of jQuery you can use promises to handle success and error callbacks like this: 在jQuery的新版本(1.5+)中,您可以使用promise来处理成功和错误回调,如下所示:
var API_KEY = 'YOUR-API-GOES-HERE';
var service_url = 'https://www.googleapis.com/freebase/v1/search';
var params = {
'query': 'Blue Bottle',
'key': API_KEY
};
$.getJSON(service_url + '?callback=?', params)
.done(function(response) {
$.each(response.result, function(i, result) {
console.log(result);
});
})
.fail(function() { console.log("error"); })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.