Ipstack的响应是“未定义”的,而文档没有解释为什么?

3

我已经完成了使用ipstack.com设置IP地址到地理位置的所有步骤,并阅读了文档。但是在我的浏览器控制台中,对象值以“未定义”返回。以下是代码:

var ip = '188.124.3.1';
var access_key = 'secret';
$.ajax({
    url: 'https://api.ipstack.com/' + ip + '?access_key=' + access_key,   
    dataType: 'jsonp',
    success: function(json) {
        var city = json.city;
        var zip = json.zip;
        var latitude = json.latitude;
        var longitute = json.longitute;
        console.log(city + ' ' + zip + ' ' + latitude + ' ' + longitute);
        console.log('success!');
        //the code reaches this stage, but returns as 'undefined' for each value above
        //execute a second ajax function to insert the values into a database.
        $.ajax({
            type: "post",
            url: "insert_geolocation.php",
            data: {
                    'zip': zip,
                    'lat': latitude,
                    'lng': longitute
                    },
            success: function (data) {
                // it's successful, do nothing else.
                // the code also reaches this stage, but the database gets a row with NULL and 0 as values...So the response from the API is returning undefined, for an unknown reason.
            },
        });
    },
    error: function(html, data) {
        console.log('Error!');
        console.log(data);
    }
});

我正在使用jQuery和文档中的JSON输出,因为我并不太了解CURL。有人能告诉我为什么会发生这种情况吗?

1个回答

1
这个问题的解决方案是因为我使用的是免费订阅计划,该计划不支持通过“ssl”进行操作。只需在成功函数中打印json(如下所示:console.log(json)),并查看它给出了哪个错误即可。

我建议看一下Ipregistry。它快速、可靠且价格便宜。支持HTTPs以及所有功能。我们不会因为对我们没有成本的功能而要求更多!您可以从100,000个免费查找开始(免责声明:我经营这项服务)。 - Laurent

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接