Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
609 views
in Technique[技术] by (71.8m points)

javascript - window.location.reload not working for Firefox and Chrome

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...