6

When running the code

$.getJSON('http://api.stackoverflow.com/0.8/questions/4', function(data) { // Do some stuff here.... }); 

I get the error

Failed to load resource

Am I accessing this wrong?

2
  • You're probably hitting some XSS blocks. Commented May 21, 2010 at 22:17
  • 1
    @Kevin: So what should I do differently? Commented May 21, 2010 at 22:25

2 Answers 2

9

I suspect your problem (as I commented) is XSS related.

Try using JSONP instead of raw JSON; we just added support for the jsonp parameter.

3
  • uh, i thought it would not be supported on v1.0 API (i remember a dev.meta post about that), good! Commented May 23, 2010 at 12:17
  • Sweet! Just what I needed. I suggest that the jsonp parameter be added to the global parameters list here stackapps.com/questions/1/api-documentation-and-help Commented May 27, 2010 at 19:52
  • Nevermind... I updated it. I keep forgetting everything is a wiki :-P Commented May 27, 2010 at 20:02
6

As Kevin says, XSS. Try this instead:

$.getJSON("http://api.stackoverflow.com/0.8/stats?jsonp=?", function(data){ alert(data.statistics[0]['total_questions']); }); 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.