0

i want see some game info on steam. I find a api, but when i use it say:

No 'Access-Control-Allow-Origin' header is present on the requested resource.

Also, I use jsonp but it is throw an error:

Uncaught SyntaxError: Unexpected token :

My code is below:

$.ajax({
    //crossDomain: 'true',
    url: 'http://store.steampowered.com/api/appdetails/?appids=730',
    //url: 'http://api.steampowered.com/ISteamApps/GetAppList/v0001/',
    //url:'http://store.steampowered.com/api/appdetails/?appids=730',
    //url:'games.json',
    type: 'get',
    dataType:'jsonp',
    //dataType:'json',
    //data = JSON.parse(data);
    crossDomain : true,
    success:function(data){
        console.log(data);
    },
    error:function(data){
        console.log("Hata ",data);
    }
});

I use anyorigin.com but it is not work. When I use local .json file working, but I need steam.

1 Answer 1

1

I don't think the URL you have in your example supports JSONP. I see this sort of JSON response:

{
  "key": "value"
}

And for JSONP it needs to be:

callback({ key: value })

There might be some confusion here about what JSONP is. JSONP requires the API serve up raw javascript. Not only that, the server must serve up a particular function call in that javascript. JSONP is a hack around cross-origin policies.

edit: As for solution, I would suggest you proxy the JSON through your own server-side application.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.