Reputation: 1
Forgive me, I'm completely new to using JSON/JSONP/AJAX and have been researching this extensively for the last 24 hours and can't figure it out. Your help would be appreciated.
I am trying to get information out of a simple JSON file from another server and display it very plainly on my website.
The JSON file I'm trying to pull information from: http://evewho.com/api.php?type=corplist&id=98224089
I'm trying to display just the character names from that JSON here inside the #characters div: http://anomaly47.com/jsonp_test.html
So far I am just trying to connect and see the objects information using the following code:
$(document).ready(function() {
var url = 'http://evewho.com/api.php?type=corplist&id=98224089&callback=?';
$.getJSON(url, null, function(data){
console.log(data);
}
)
});
I keep getting the following error in the console:
Uncaught SyntaxError: Unexpected token : api.php?type=corplist&id=98224089&callback=jQuery1111010067848535254598_1425072137785&_=14250721377…:1
I'm not sure what I'm doing wrong here.
Thanks again!
Upvotes: 0
Views: 698
Reputation: 171669
Not all API's that serve json are accessible using ajax.
Your API is not returning jsonp
data format and is not CORS enabled.
If it is your site, and you are making request from the same domain, remove the &callback=?
from url since this tells jQuery that request is for jsonp
.
If it is a cross domain request you will need to set up a proxy on your server to retrieve the data and make your ajax call to your proxy script
Upvotes: 1