Ответы Ipstack являются «неопределенными», и документация не объясняет почему? - PullRequest
0 голосов
/ 03 февраля 2019

Я выполнил все шаги по настройке ip-to-geolocation с помощью ipstack.com и прочитал документацию .Но значения объекта возвращаются как «неопределенные» в моей консоли браузера.Вот как выглядит код:

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 Ответ

0 голосов
/ 04 февраля 2019

Решение этой проблемы заключалось в том, что у меня был бесплатный тарифный план, и он не предлагает проходить через ssl.Просто напечатайте json следующим образом: console.log(json) внутри функции успеха и посмотрите, какую ошибку она вам выдаст.

...