jquery 獲取客戶端ip地址 和 地區位置
阿新 • • 發佈:2018-11-11
搜狐IP地址查詢介面(預設GBK):http://pv.sohu.com/cityjson
搜狐IP地址查詢介面(可設定編碼):http://pv.sohu.com/cityjson?ie=utf-8
使用搜狐介面demo:
<p id="ip"></p> <script src="../plugins/jQuery/jquery-1.12.4.min.js"></script> <script src="http://pv.sohu.com/cityjson"></script> <script type="text/javascript"> $(function() { $('#ip').html(returnCitySN["cip"]); })
獲取具體的地區位置demo:
//獲取城市ajax $.ajax({ url: 'http://api.map.baidu.com/location/ip?ak=ia6HfFL660Bvh43exmH9LrI6', type: 'POST', dataType: 'jsonp', success:function(data) { $('#city').html(data.content.address_detail.province + "," + data.content.address_detail.city) } }); }) </script> </body> </html>
效果圖: