2014-09-22 60 views
3

我想用maxmind javascript獲取用戶的IP,位置,城市,國家等,但我得到空 我有什麼錯誤嗎?如何使用maxmind獲取ip信息javascript

我也有問題可以將maxmind javascript放到我的插件中以供無限使用嗎?

我的JavaScript這裏:

<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這裏

<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> 

回答

1

你爲什麼要使用document.write一個jQuery命令裏面?以下內容正確輸出我的位置。根據使用限制,您必須閱讀their terms of service

$("#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>

+1

工作感謝名單:) 但如果我使用的MaxMind的JS到我的網站,每天50000的印象....它是免費的?爲用戶? – 2014-09-22 07:30:03

+1

我不知道,他們的網頁說你必須付錢。 – brasofilo 2014-09-22 07:31:05

+1

:)謝謝你的兄弟:) – 2014-09-22 08:11:19