views:

44

answers:

1

I am trying to get json data from a url. Url is working ok in FF. I am trying code like this

$.getJSON("http://testsite.com/1234/?callback=?", function(data){   
        //here i am getting invalid label error**
    }
);

When i am trying without callback=? i am getting empty data

$.getJSON("http://testsite.com/1234/", function(data){   
            //here i am data = ""
        }
    );

Whats going wrong?

+2  A: 

It looks like the site you're fetching from doesn't support JSONP, with this URL:

http://testsite.com/1234/?callback=?

It's trying to use JSONP, but the server is returning a plain JSON response (not wrapped in a function).

With this URL:

http://testsite.com/1234/

It's not trying JSONP at all, and being blocked by the same-origin policy.


To fetch data from a remote domain, it needs to support JSONP so it can be grabbed with a GET request, so you'll need to either add support to that domain, or proxy the request through your own.

Nick Craver
Yes its showing only json data. But in FF the url is working ok. I need that json object to be returned in some variable.
coure06
@coure06 - The response *isn't* ok, that's the point, you're getting `{...data...}` what you *need* to get is `functionName({...data...})`, the server isn't returning this, so you're getting an invalid label syntax error.
Nick Craver
How to "proxy the request" through my own?
coure06
@coure06 - Yahoo has a good writeup on this: http://developer.yahoo.com/javascript/howto-proxy.html
Nick Craver