最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bing search API using Jsonp not working, invalid label - Stack Overflow

programmeradmin1浏览0评论

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=".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.

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

Share Improve this question asked May 13, 2010 at 19:39 BlankmanBlankman 267k331 gold badges795 silver badges1.2k bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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

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.',
    dataType: 'jsonp',
    jsonp: 'jsonp'
});`

发布评论

评论列表(0)

  1. 暂无评论