0

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?

coure2011
  • 40,286
  • 83
  • 216
  • 349

1 Answers1

4

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
  • 623,446
  • 136
  • 1,297
  • 1,155
  • 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. – coure2011 Oct 11 '10 at 20:49
  • @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 Oct 11 '10 at 20:56
  • How to "proxy the request" through my own? – coure2011 Oct 11 '10 at 20:57
  • @coure06 - Yahoo has a good writeup on this: http://developer.yahoo.com/javascript/howto-proxy.html – Nick Craver Oct 11 '10 at 20:58