如何处理来自外部网址的数据? [英] How to address data from external url?

查看:96
本文介绍了如何处理来自外部网址的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我有了这个代码:

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

并收到此错误:


未捕获的SyntaxError:意外的令牌:

Uncaught SyntaxError: Unexpected token :

我可以在控制台中看到来自网址的正确响应并尝试了不同的数据类型。可能有什么问题?

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

推荐答案

请试试这个。在我的结尾,这是有效的。

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) {

            }
        });

这篇关于如何处理来自外部网址的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆