window.location.reload不适用于Firefox和Chrome [英] window.location.reload not working for Firefox and Chrome

查看:247
本文介绍了window.location.reload不适用于Firefox和Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变一个按钮的用户状态,所以我所做的就是检测当前的状态,如果需要的话改变。

但是在这种情况改变了后端的状态,但是显示页面需要刷新的状态,因为在刷新时会检查当前状态并显示。所以我使用window.location.reload属性来显示页面上的最新状态

所有的东西在IE中工作正常。但是在Firefox和Chrome的情况下,状态不会改变。我认为window.location.reload不起作用,因为当我只是评论这一行,并尝试点击按钮,手动刷新页面,它显示更改状态。



请问我应该用什么来在Firefox和Chrome中使用这个工具?



当我在Google上搜索时,发现它在Firefox和Chrome中可用,在setTimeout()中。我试过了,但即使那样它也不适合我。

 < script> 
$ b $(document.body).on('click','#activate',function(){
var pkgVersion = $(this).attr('data-version') ;
alert(@ Url.Action(SetActivePackage,Deployment),{version:pkgVersion});
$ .get(@ Url.Action(SetActivePackage,Deployment ),{version:pkgVersion})。done(function(){
$ b $)};
setTimeout(function(){window.location.reload(data);},0 );
});
< / script>

请建议!

解决方案

  history.go(0); 




  window.location.href = window.location.href; 

我没有在Firefox和Chrome上测试它,但它可以帮助您更快。明天我会做测试和更新答案,如果这不起作用。

编辑



我已经派了一个jsFiddle向你展示一些例子:

http://jsfiddle.net/Zanelli/kpJxU/1/

我希望有人为你工作(这里都工作过罚款)。


I want to change the user status on click of a Button, so all I am doing is, detecting the current status and changing, if needed.

But in this case the changes the status in backend, but to show the status the page needs to be refreshed, as on refresh it checks the current status and shows. So I am using the "window.location.reload" property to show the latest status on page

All the things are working fine in IE. But in case of Firefox and Chrome, The status is not changing. I think "window.location.reload" is not working, because when I just comment this line and try clicking the button and manually refresh the page it shows the changes Status.

Can you please suggest what should I use to make this work in Firefox and Chrome?

When I googled, I found somewhere it works in Firefox and Chrome if you give it in "setTimeout()". I tried it, but even then its not working for me.

<script>

    $(document.body).on('click', '#activate', function () {
        var pkgVersion = $(this).attr('data-version');
        alert("@Url.Action("SetActivePackage", "Deployment")", { version: pkgVersion });
        $.get("@Url.Action("SetActivePackage", "Deployment")", { version: pkgVersion }).done(function () {

        });
         setTimeout(function () { window.location.reload(data); }, 0);
    });
</script>

Please suggest!

解决方案

I have two other options to you:

history.go(0);

And:

window.location.href = window.location.href;

I'm not tested it on Firefox and Chrome yet, but it may help you faster. Tomorrow I'll do the tests and update the answer if this not work.

EDIT

I've forked a jsFiddle to show you some examples:

http://jsfiddle.net/Zanelli/kpJxU/1/

I hope someone work for you (here all worked fine).

这篇关于window.location.reload不适用于Firefox和Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆