在表单提交上显示加载消息 - 后退按钮问题

发布于 2024-10-07 01:51:12 字数 268 浏览 0 评论 0原文

提交表单时,我显示了一个带有加载消息和图像的 div:

$("#some_form").submit(function(){
  $("#some_form #loading").show();
});

这按我的预期工作。但是,如果您使用后退按钮返回,加载的 div 仍然可见,因为浏览器尚未重新加载页面。

当使用后退按钮时,是否有一个浏览器事件可以用来隐藏加载 div?或者也许我以错误的方式处理整件事?

感谢您的帮助!

I'm showing a div with a loading message and image when a form is submitted:

$("#some_form").submit(function(){
  $("#some_form #loading").show();
});

This works as I expected. But, if you use the back button to go back, the loading div is still visible because the browser has not reloaded the page.

Is there a browser event I could use to hide the loading div when the back button is used? Or perhaps I'm going about the whole thing the wrong way?

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深白境迁sunset 2024-10-14 01:51:12

由于您正在显示“正在加载”图像,因此您可能正在使用 AJAX。正确的?您应该使用 ajax-start 和 ajax-complete 事件 =)

编辑:
您可以尝试:

 window.onbeforeunload = function() {

     $("#some_form #loading").hide();

 }

或者这样:

http://www.bajb.net /2010/02/浏览器后退按钮检测/

Since you're showing the 'loading' image, you're probably working with AJAX. Right? You should use the ajax-start and ajax-complete events =)

EDIT:
You could try:

 window.onbeforeunload = function() {

     $("#some_form #loading").hide();

 }

Or this:

http://www.bajb.net/2010/02/browser-back-button-detection/

牛↙奶布丁 2024-10-14 01:51:12

如何使用标头 Cache-Control: no-cache 告诉浏览器不要缓存原始页面?当返回历史记录时,应强制其重新加载页面。

window.onunload 怎么样?

How about using a header Cache-Control: no-cache telling the browser not to cache the originating page? When navigating back in the history should force it to reload the page.

How about window.onunload ?

简美 2024-10-14 01:51:12

你可以

<script>
$(function() { 
    $("#some_form #loading").hide(); 
});
</script>

在心里加上去。因此,只要页面完全加载,它就会隐藏 div。据我所知,当按下后退按钮时,这也应该起作用。

You could add

<script>
$(function() { 
    $("#some_form #loading").hide(); 
});
</script>

in your head. So it hides the div whenever the page is fully loaded. This should also work when the back button is pressed as far as I know.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文