jsonp Uncaught SyntaxError: Unexpected token :

jsonp Uncaught SyntaxError: Unexpected token :

我想在 Steam 上查看一些游戏信息。我找到了 api,但是当我使用它时说:

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

此外,我使用 jsonp 但它会引发错误:

Uncaught SyntaxError: Unexpected token :

我的代码如下:

$.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);
    }
});

我使用 anyorigin.com 但它不起作用。当我使用本地 .json 文件工作时,但我需要 steam.

我认为您示例中的 URL 不支持 JSONP。我看到这种 JSON 响应:

{
  "key": "value"
}

对于 JSONP,它需要是:

callback({ key: value })

这里可能对 JSONP 是什么有些混淆。 JSONP 需要 API 生吃 javascript。不仅如此,服务器还必须在 javascript 中提供 特定 函数调用。 JSONP 是关于跨源策略的 hack。

编辑: 至于解决方案,我建议您通过自己的服务器端应用程序代理 JSON。