Javascript Rails中的navigator.geolocation调用(签入/签出函数)后页面不更新
我使用的是标准的HTML5定位服务。用户进入咖啡馆,打开应用程序,单击“签入!”,应用程序获取位置并使用它,直到用户稍后单击“签出!” 在我的查看器中,我调用了一个包含navigator.geolocation的脚本,它完成了它的工作。我成功地将纬度和经度参数传递给我的控制器,它会更新所有内容。但是,当所有这些都完成后,我将_重定向到root_url,新页面就不会刷新了(我知道在某个时候我应该更优雅地更新链接部分,但现在,我只想让它继续运行并了解发生了什么)。这是我的密码: 在我的查看器中-Javascript Rails中的navigator.geolocation调用(签入/签出函数)后页面不更新,javascript,ruby-on-rails,Javascript,Ruby On Rails,我使用的是标准的HTML5定位服务。用户进入咖啡馆,打开应用程序,单击“签入!”,应用程序获取位置并使用它,直到用户稍后单击“签出!” 在我的查看器中,我调用了一个包含navigator.geolocation的脚本,它完成了它的工作。我成功地将纬度和经度参数传递给我的控制器,它会更新所有内容。但是,当所有这些都完成后,我将_重定向到root_url,新页面就不会刷新了(我知道在某个时候我应该更优雅地更新链接部分,但现在,我只想让它继续运行并了解发生了什么)。这是我的密码: 在我的查看器中-
<% if (@voterinfo.checkin == 0) %>
<li>
<h4> <%= link_to "-->Check-In!", "#", :id => 'findMe' %> </h4>
<script>
$(function(){
$("a#findMe").click(function(){
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
$.post('/users/set_geolocation/', {latitude: position.coords.latitude,
longitude: position.coords.longitude,
dataType: 'float'});
}, function () {
alert('We couldn\'t find your position.');
});
} else {
alert('Your browser doesn\'t support geolocation.');
}
});
})
</script>
</li>
<% else %>
<li> <h4><%= link_to "--->CHECK-OUT!", :controller => :users,
:method => :set_geolocation %></h4></li>
<% end %>
</ul>
<% end %>
结束
感谢您在此提供的帮助。“但当所有操作完成后,我将_重定向到root_url,新页面不会刷新”—因此很可能是一个简单的缓存问题;因此,在进行重定向时应用一种常见的“缓存破坏”技术。
def set_geolocation
@user = current_user
@voterinfo = Voterinfo.find_by_user_id(@user.id)
if (@voterinfo.checkin == 0)
@user.update_attributes(:longitude => params['longitude'], :latitude => params[:latitude])
@user.save(validate: false)
sign_in(@user)
@voterinfo.checkin = 1
@voterinfo.save
redirect_to root_url
else
@voterinfo.checkin = 0
@voterinfo.save
redirect_to root_url
end