I'm really new to the world of JSON goodness, and am really struggling to get a cross-domain request to work. Really doing my head in :(
The code I have is:
$.getJSON('http://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/?language=en_us&key=<MY KEY HERE>&callback=?', function(data) {
alert("success");
});
From what I can understand, adding the &callback=? to the end of the url means it will call the function I have next, which should pop up a simple alert box. For some reason this never happens though. When looking in Firebug, I can see the Response fine and the expected data results are in there....yet my function is never called. If however, I try to define a specific function for the callback, I do not get a response. Really confused and would GREATLY appreciate any help.
Thanks guys!
Try this code:
$.ajax({ url:'http://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/?language=en_us&key=<MY KEY HERE>',
dataType:'jsonp',
succes:function(data) {
alert("success");
}
});
$.getJSON
- it is for json only. But $.ajax
with dataType:'jsonp',
will add callback correctly
You could use the ajax()
method instead like this:
$.ajax({
url: "'http://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/?language=en_us&key=<MY KEY HERE>",
cache: false,
dataType: 'jsonp',
success: function( data ){
alert("success");
}
});