【问题标题】:Jquery JSON call: Uncaught SyntaxError: Unexpected token :Jquery JSON 调用:未捕获的 SyntaxError:意外令牌:
【发布时间】:2015-04-18 20:45:31
【问题描述】:

我希望我的网站能够检索如下蒸汽商品价格:

http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=Operation%20Phoenix%20Weapon%20Case

现在我有这个代码:

$.ajax({
    type : "Get",
    url : "http://steamcommunity.com/market/priceoverview",
    data :"currency=3&appid=730&market_hash_name=" + steaminfo_inventory[3][index][7],
    dataType :"jsonp",
    jsonp: false,
    success : function(data){
        alert(data);},
});

我不断收到错误消息:Uncaught SyntaxError: Unexpected token :。似乎我仍在接收数据,但仍然收到错误消息。当我点击 chrome 中的错误时,我看到了这个输出:{"success":true,"lowest_price":"0,06€","volume":"107,179","median_price":"0,06€ "}

感谢任何帮助。

【问题讨论】:

标签: jquery ajax steam steam-web-api


【解决方案1】:

如果使用 JSONP,必须设置回调函数作为响应。 jQuery 在 get 参数中添加了自动回调。

尝试将后端的响应更改为 GETcallback;

示例: 网址 -> http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=Operation%20Phoenix%20Weapon%20Case&callback=testCallback

响应 -> testCallback({"success":true,"lowest_price":"0,06€","volume":"107,179","median_price":"0,06€ "});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-25
    相关资源
    最近更新 更多