0

I am trying to do a JSONP request for data from http://soarforward.com/ClassDocuments, but it's not working.

If you go to the URL you can see the JSON. I am converting an ASP.net object to JSON myself, so if the javascript is invalid I can modify it.

Here is my example code : http://jsfiddle.net/guanome/JDLqf/

function getFiles() {
    var url = "http://soarforward.com/ClassDocuments";
    $.getJSON(url + "?callback=?", null, function(result) {
        console.log(result);
    });
}
$(document).ready(function() {
    getFiles();
});
FarFigNewton
  • 7,108
  • 13
  • 50
  • 77
  • Try adding this arguments to your $.getJSON() call: dataType:'jsonp' If it's still not working try adding: jsonp: 'jsonp' – paparush Nov 05 '11 at 23:11
  • 1
    The sever does not seem to return JSONP. http://soarforward.com/ClassDocuments?callback=foo still returns JSON. – Felix Kling Nov 05 '11 at 23:12
  • @paparush: Such options are only accepted by `$.ajax`. – Felix Kling Nov 05 '11 at 23:13
  • @FelixKling - You're absolutely correct. I spoke too soon. – paparush Nov 05 '11 at 23:16
  • @FelixKling what do I need to do to my page to have it return JSONP? – FarFigNewton Nov 05 '11 at 23:41
  • 1
    See [Wikipedia](https://secure.wikimedia.org/wikipedia/en/wiki/JSONP) for details. The server has to return something like `valueOfCallbackParameter(jsonHere);` – Felix Kling Nov 05 '11 at 23:47
  • @FelixKling That fixed it, I knew I was missing something to do JSONP. Can you tell me why this twitter example works but mine didn't? http://stackoverflow.com/questions/2681466/jsonp-with-jquery. From what I could tell, they don't have a callback function either. – FarFigNewton Nov 06 '11 at 00:06
  • I don't know the URL provided there does not work at all for me. But compare the different results of https://api.twitter.com/1/statuses/user_timeline.json?screen_name=codinghorror and https://api.twitter.com/1/statuses/user_timeline.json?screen_name=codinghorror&callback=foo – Felix Kling Nov 06 '11 at 00:13
  • @FelixKling they used the same jquery method that I did with this url, http://api.twitter.com/1/statuses/user_timeline/codinghorror.json. It returns a JSON object without the callback, yet I am able to access it in this example without cross domain issues, http://jsfiddle.net/guanome/uD6ke/ – FarFigNewton Nov 06 '11 at 00:18
  • I don't understand, in your example you are also adding `"?callback=?"` to the domain. That indicates that the server should return JSONP and then it does. Or am I misunderstanding you? – Felix Kling Nov 06 '11 at 00:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/4761/discussion-between-guanome-and-felix-kling) – FarFigNewton Nov 06 '11 at 00:22

1 Answers1

0

I forgot to wrap my return JSON in a function call.

I was returning

{"foo" : "bar"}

instead of

fooBar({"foo" : "bar"});
FarFigNewton
  • 7,108
  • 13
  • 50
  • 77