function getIP() {
var ipAddress = 'Unknown IP';
$.ajax({
dataType: "json",
url: "http://smart-ip.net/geoip-json?callback=?",
async: false,
success: function(data) {
ipAddress = data.host;
}
});
return ipAddress;
}
var ipAddress = 'Unknown IP';
function getIP() {
return $.getJSON("http://smart-ip.net/geoip-json?callback=?");
}
getIP().then(function(info) {
ipAddress = info.host;
});
alert(ipAddress);
async (default: true)
Type: Boolean
By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation.
You're using JSONP (callback=?)
You're doing a cross-domain requests (http://smart-ip.net)
What about : http://jsfiddle.net/mB22D/
Open in new window