7

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?

Peter Mortensen
  • 375
  • 1
  • 3
  • 10
Kredns
  • 213
  • 1
  • 7

2 Answers2

10

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.

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

As Kevin says, XSS. Try this instead:

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