I done all the steps to setting up a ip-to-geolocation by using ipstack.com, and read through the documentation. But the object values are returned as 'undefined' in my browser console. This is how the code looks: javascript/jquery code
var ip = '188.124.3.1';
var access_key = 'secret';
$.ajax({
url: '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);
//the console says: 'undefined undefined undefined undefined'
console.log('success!');
$.ajax({
type: "post",
url: "insert_geolocation.php",
data: {
'zip': zip,
'lat': latitude,
'lng': longitute
},
success: function (data) {
},
});
},
error: function(html, data) {
console.log('Error!');
console.log(data);
}
});
I use jQuery and JSON output , because I don't know CURL. Can anyone tell me why it return undefined?
j
stuff ;)
I would suggest to check your JSON :)
console.log(json);