单击浏览器刷新按钮时的Ajax调用 [英] Ajax call when click on Browser refresh Button
本文介绍了单击浏览器刷新按钮时的Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Ajax深度链接方面苦苦挣扎,想知道当用户单击浏览器刷新"按钮时是否可以进行Ajax调用.
Im struggling with Ajax Deep linking and wonder if is possible to make an Ajax call when user click on Browser refresh button.
我尝试使用 beforeunload
可行,但是在ajax调用之后仍然向服务器发出请求?有没有办法阻止对服务器的请求?
I tried to use beforeunload
It works but still make a request to the server after the ajax call Is there a way to prevent the request to the server ?
$(window).on('beforeunload',function(e){
//ajax call here.
});
推荐答案
了解用户单击刷新的时间是不容易的.从浏览器的角度来看,他们只是在离开页面浏览.您可以使用onbeforeunload方法进行操作...
There is no hook into knowing when a user clicks refresh. From a browser perspective they are simply navigating away from the page. You could hook into the onbeforeunload method to do something...
window.onbeforeunload = function(){ return 'Testing...' }
这篇关于单击浏览器刷新按钮时的Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文