我正在开发一个博客应用程序,但我遇到了一个问题
我想做的事
我正在尝试访问用户位置,如:-城市或州。我不想进入地图。我只想访问用户的城市名称
我试过什么
我尝试通过JavaScript
和Google Apis
访问位置,它完美地显示了位置。但我没有找到任何方法将用户在数据库中的位置从前端保存到后端。所以我放弃了这个方法。下面↓ 代码正在显示FrontEnd Code of JavaScript
<script>
let thisElement = $(this)
$.ajax({
url: "https://geolocation-db.com/jsonp","/update_counter/",
jsonpCallback: "callback",
dataType: "jsonp",
success: function(location) {
$('#country').html(location.country_name);
console.log('success')
thisElement.parent().parent().fadeOut();
}
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div>Country: <span id="country"></span></div>
然后我试着MaxMind's GeoIP
它对我也不起作用。(答案也太旧了)
然后我尝试了THIS,但它们并没有连接到任何模型,所以可能很难在数据库中保存用户位置
我不知道该怎么办
任何帮助都将不胜感激
先谢谢你
使用Ajax
在得到你的位置后。使用Ajax将其发送到django,然后使用django保存到db
网址:
观点:
相关问题 更多 >
编程相关推荐