views:

174

answers:

1

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.

+2  A: 

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

bobince
if I change the datatype to json, i get an error in the request, with a status complete.
Blankman
Yep, you can't access JSON from an external domain, for security reasons. That's why JSONP was invented.
bobince
should the JsonCallback be the name of the function or the actual .js code?
Blankman