Get country code using javascript

<>

This question already has an answer here:

Answers


According to the docs on the website, you should be able to retrieve the country code with ipinfo. try using $.getJSON instead of $.get

var country_code = null;
$.getJSON('http://ipinfo.io/' + userip, function(data){
    country_code = data.country;
    alert(country_code);
});

I have used the below code using jQuery and its working fine for me. I am getting the country_code , country_name etc.,.

 jQuery(document).ready(function($) {
    jQuery.getScript('http://www.geoplugin.net/javascript.gp', function() 
    {
        var country = geoplugin_countryName();
        alert(country);
        var code = geoplugin_countryCode();
        alert(code);
        console.log("Your location is: " + country + ", " + zone + ", " + district);
    });
});

Note: Do remember to import the plugin script as below:

<script src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>


Need Your Help

Having Trouble Applying HTTPS to Proper Site Areas

.htaccess https

New to developing. I am attempting to apply HTTPS to certain pages of my site, while others remain unsecure. I have experimented with my .htaccess file but remain stuck. Any help would be greatly

python azure blob storage md5 check fails on blob upload using put_block_blob_from_path

python azure hash md5 azure-storage-blobs

I am trying to upload a blob to azure blob storage with python sdk. I want to pass the MD5 hash for validation on the server side after upload.