使用 Jsonp 的 Bing 搜索 API 不起作用,标签无效

发布于 2024-09-01 07:31:54 字数 686 浏览 1 评论 0原文

在处理 Bing 的 json 请求(bing 搜索,而不是地图)时,我收到一条错误,提示“无效标签”。

我的查询网址是:

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 reports 'invalid label' and then dumps the json response。

不知道出了什么问题?帮助表示赞赏。

Struggling with Bing's json request (bing search, not map), I am getting an error back that says 'Invalid Label'

My query url is:

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 reports 'invalid label' and then dumps the json response.

No idea what is wrong? help appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请帮我爱他 2024-09-08 07:31:54

您发布的 Bing API URL 不是 JSONP,而是纯 JSON。

JSONP 被解释为原始 JavaScript,在这种情况下,JSON 对象的 {"something": ... 语法不是对象文字,而是带有名称包含引号的标签的块语句(因此无效)。

据我了解,如果您想要来自 Bing 的 JSONP,您必须告诉通过传入参数 ...&JsonType=callback&JsonCallback=(全局回调函数的名称)。

(我也不确定 data: "{}" 会做什么,但我不认为有什么好处。)

The Bing API URL you posted isn't JSONP, it's plain JSON.

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).

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).

(I'm also not sure what data: "{}" will do, but I don't think anything good.)

递刀给你 2024-09-08 07:31:54

本着保持最新的精神,较新的 Bing REST API 确实支持 jsonp,您只需确保“callback”参数为“jsonp”即可。在 jQuery 中,只需将 $.ajax() 调用中的 jsonp 属性更改为“jsonp”即可完成此操作。

$.ajax({
    url: 'http://some.domain.com',
    dataType: 'jsonp',
    jsonp: 'jsonp'
});`

Just in the spirit of keeping things up-to-date, the newer Bing REST API does support jsonp, you just have to make sure that the "callback" parameter is "jsonp". In jQuery just change the jsonp attribute in your $.ajax() call to "jsonp" to make this work.

$.ajax({
    url: 'http://some.domain.com',
    dataType: 'jsonp',
    jsonp: 'jsonp'
});`

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文