Bing搜索API使用Jsonp无效,标签无效 [英] Bing search API using Jsonp not working, invalid label
问题描述
挣扎着Bing的json请求(bing搜索,而不是地图),我收到一条错误回复,上面写着'无效标签'
Struggling with Bing's json request (bing search, not map), I am getting an error back that says 'Invalid Label'
我的查询网址是:
var bingurl="http://api.search.live.net/json.aspx?Appid=##APIKEY##&query=Honda&sources=web";
$.ajax({
type: "GET",
url: bingurl,
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function(data) {
$callBack(data);
},
error: function(msg) {
alert("error" + msg);
}
});
Firebug报告'无效标签'然后转储json响应。
Firebug reports 'invalid label' and then dumps the json response.
不知道出了什么问题?帮助赞赏。
推荐答案
您发布的Bing API网址不是JSONP,它是普通的JSON。
The Bing API URL you posted isn't JSONP, it's plain JSON.
JSONP被解释为原始JavaScript,在这种情况下,JSON对象的 {something:...
语法不是object literal,但是带有标签的块语句,其名称包含引号(因此无效)。
JSONP is interpreted as raw JavaScript, in which case a JSON object's {"something": ...
syntax is not an object literal, but a block statement with a label whose name contains quotes (hence the invalidness).
根据我的理解,如果你想从Bing获得JSONP,你必须告诉它通过传入参数 ... & JsonType = callback& JsonCallback =
(全局回调函数的名称)。
As I understand it, if you want JSONP from Bing you have to tell it that by passing in parameters ...&JsonType=callback&JsonCallback=
(name of global callback function).
(我也不确定<$ c $是什么c>数据:{}会做,但我觉得没什么好处。)
(I'm also not sure what data: "{}"
will do, but I don't think anything good.)
这篇关于Bing搜索API使用Jsonp无效,标签无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!