IP to Location using Javascript

后端 未结 13 1403
死守一世寂寞
死守一世寂寞 2020-11-27 03:46




        
13条回答
  •  攒了一身酷
    2020-11-27 04:07

    It's quite easy with an API that maps IP address to location. Run the snippet to get city & country for the IP in the input box.

    $('.send').on('click', function(){
    
      $.getJSON('https://ipapi.co/'+$('.ip').val()+'/json', function(data){
          $('.city').text(data.city);
          $('.country').text(data.country);
      });
    });
    
    
    
    
    

    ,

提交回复
热议问题