vendredi 24 juillet 2020

Getting info out of jquery and assigning it to a variable for using it in javascript

I am having trouble getting country code out of jquery.

I can get the users information using the IP. I want to get country code out of it and assign it to a variable so i can use it insid a function.

Here is the code i am using;

<!DOCTYPE html>
<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <script>
        $.get("http://ipinfo.io", function (response) {
              $("#ip").html("IP: " + response.ip);
              $("#address").html("Location: " + response.city + ", " + response.region);
              $("#details").html(JSON.stringify(response, null, 4));
        }, "jsonp");
      </script>
</head> 
<body>
    <h3>Client side IP geolocation using <a href="http://ipinfo.io">ipinfo.io</a></h3>

<hr/>
<div id="ip"></div>
<div id="address"></div>
<hr/>Full response: <pre id="details"></pre>
</body>
</html>

Here i want to use the country code and assign to a variable.

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire