Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
Cómo obtener el nombre del país del visitante para el sitio web

Actualmente estoy trabajando en mi sitio web que muestra varios lugares según el país del visitante.

También probé con estos ejemplos, pero quiero obtener la dirección IP automáticamente.

aquí hay un código de ejemplo

HTML

 <input type="text" id="ip" /> <input type="button" value="Get country of IP" id="submit" />

JavaScript

 <script type="text/javascript"> $(function() { $("#submit").click(function() { if ($('#ip').val()) { var ip = $('#ip').val(); // the request will be to http://www.geoplugin.net/json.gp?ip=my.ip.number but we need to avoid the cors issue, and we use cors-anywhere api. $.getJSON("https://cors-anywhere.herokuapp.com/http://www.geoplugin.net/json.gp?ip=" + ip, function(response) { console.log(response); // output an object which contains the information. $("#content").html("Hello visitor from " + response.geoplugin_countryName); }); } else { alert("Please provide a IP"); } }); }); </script>

soy nuevo en PHP así que por favor guíame... Gracias :)

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Prueba el siguiente código

 // Jquery $.getJSON("http://freegeoip.net/json/", function(data) { var ip = data.ip; var country = data.country_name; $("#ip").val(ip); $("#content").html("Hello visitor from " + country); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="ip" /> <input type="button" value="Get country of IP" id="submit" /> <div id="content"> </div>

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!