When I call the function with console.log(ip2db())
it prints undefined
. How can i return the value returned from ip2db.php
?
Here is my code:
function ip2db(){
var result;
$.getJSON('https://api.ipgeolocation.io/ipgeo?apiKey=a759dab4af1f462496dda90b3575f7c7', function(data) {
var ip_data = JSON.stringify(data, null, 2);
$.post("https://mywebsite.com/ip2db.php",
{
ip_data
},
function(data, status){
console.log("data: " + data + "\nStatus: " + status);
CreateUserStorage(data);
result = data;
}
);
});
return result;
}