Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - IP address Show Country

i have a question. i want perline IP address show country use http://ipinfo.io

this html code

<span>192.110.160.11</span><br>
<span>177.67.82.22</span><br>
<span>36.75.102.33</span><br>

my js

document.body.innerHTML = document.body.innerHTML.replace(new RegExp("<span>(.*?)</span>", "g"),"<span id='ip'>$1</span> - <span id='country'>wait..</span>");

var ip = document.getElementById("ip").innerHTML;

$.get("http://ipinfo.io/"+ip, function (response) {
$("#country").html(response.country);
}, "jsonp");

result my js , http://jsfiddle.net/p26uE

192.110.160.11 - US
177.67.82.22 - wait..
36.75.102.33 - wait..

i want result

192.110.160.11 - US
177.67.82.22 - BR
36.75.102.33 - ID

Thanks for everybody who can help me :D

like image 474
james bond Avatar asked May 14 '26 16:05

james bond


1 Answers

$("span").each(function(i){
    var self = this;
    var ip = $(this).text();
    $.get("http://ipinfo.io/"+ip, function (response) {
         $(self).html(ip+"-"+response.country);
    }, "jsonp");
});

Check this

JSFIDDLE

like image 127
Subash Selvaraj Avatar answered May 17 '26 06:05

Subash Selvaraj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!