How to address data from external url?

可紊 提交于 2019-12-08 09:39:26

问题


Now I have that code:

$(document).ready(function() {
 $.ajax({
    type: "POST",
    url: "http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=StatTrak%E2%84%A2%20P250%20%7C%20Steel%20Disruption%20%28Factory%20New%29",
    data: {},
    dataType: "jsonp",
    crossDomain: true,
    success: function(data) {
      console.log(data)
    }  });
});

and get this error:

Uncaught SyntaxError: Unexpected token :

I can see the right response from the url in my console and tried different dataTypes. What could be wrong?


回答1:


Please try this. On my end this works.

$.ajax({
            type: "POST",
            url: "http://steamcommunity.com/market/priceoverview/?currency=3&appid=730&market_hash_name=StatTrak%E2%84%A2%20P250%20%7C%20Steel%20Disruption%20%28Factory%20New%29",
            data: {},
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                // an example of using result
        var myVar1 = result.lowest_price;
        var myVar2 = result.median_price;
        var myVar3 = result.success;
        var myVar4 = result.volume;

        alert(result.success);
            },
            error: function (result) {

            },
            fail: function (arg1, arg2, arg3) {

            }
        });


来源:https://stackoverflow.com/questions/29510317/how-to-address-data-from-external-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!