How to access information using maxmind javascript

I want to get ip, location, city, country, etc. with maxmind javascript but i got null is there any error?

Also I have a question, can I put maxmind javascript in my plugin for unlimited use?

My javascript is here:

<script src="http://j.maxmind.com/app/geoip.js"></script>
<script>
    $("#country").html(document.write(geoip_country_code()));
    $("#countryname").html(document.write(geoip_country_name()));
    $("#city").html(document.write(geoip_city()));
    $("#region").html(document.write(geoip_region()));
    $("#regionname").html(document.write(geoip_region_name()));
</script>

      

HTML HERE

<div id="country">&nbsp;</div>
<div id="countryname">&nbsp;</div>
<div id="city">&nbsp;</div>
<div id="region">&nbsp;</div>
<div id="regionname">&nbsp;</div> 

      

+3


source to share


1 answer


Why are you using document.write

jQuery inside the command? The following results display my location correctly. In accordance with the restrictions of use, you will have to read their terms of use .



$("#country").html( 'Country: ' + geoip_country_code() );
$("#countryname").html( 'Country name: ' + geoip_country_name() );
$("#city").html( 'City: ' + geoip_city() );
$("#region").html( 'Region: ' + geoip_region() );
$("#regionname").html( 'Region name: ' + geoip_region_name() );
      

div:nth-of-type(odd) {
    background: #e0e0e0;
}
div:nth-of-type(even) {
    background: #a5a5a5;
}
div {
    padding: 5px;
    margin: 5px;
}
      

<script src="http://j.maxmind.com/app/geoip.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="country"></div>
<div id="countryname"></div>
<div id="city"></div>
<div id="region"></div>
<div id="regionname"></div>
      

Run codeHide result


+1


source







All Articles