window.location.href works only after clearing browser cache on IE

大城市里の小女人 提交于 2019-12-24 09:48:15

问题


I have stuck with really weird issue.

Here is code sample

$.ajax({
    method: "POST",
    data: content,
    url: '/signin/',
    success: function (response) {
        window.location.href = 'test.html';
    }, 
    error: function (xhr, status, err) {
        errorHandler(xhr);
    }
});

First I thought redirection works only after opening debugger, and searched in that direction.
According to results and threads I commented all console.log statements. No luck.

Then found that only redirection is not working.
Then I tried
window.location.replace("test.html");,
window.location.assign("test.html");,
window.location.href = test.html,
window.open('test.html','_self', null , false);, setTimeout('window.navigate("test.html");', 1); still no luck..

Now I figured out when I open debugger and clear browser's cache and close the debugger again, then redirection works only once not after that.

To get redirection work I have to either clear the browser's cache everytime or have to keep debugger open.

How do I get redirection work without opening developer tool?

I Appreciate the help.

Thanks.


回答1:


for this maybe because your browser is caching the content... lets see if you are using chrome, and you open developer mode, you can see this:

and maybe something equivalent..

well, this is quite annoying as for javascript development because we have to open up the developer tools to make sure our script is not cached by browser. But since browser are intended primarily for consumer, not developer, we are the one who have to adjust ourselves to the browser, including either clear cache everytime, or let the developer window open.

hope this help

Edit: hope this help in case you use IE:




回答2:


Actully redirection was not an issue.
There was another bizzare issue, IE was using cached response when developer tool is not open as explained in this answer.

So I just had add cache : false to my ajax request.



来源:https://stackoverflow.com/questions/40629171/window-location-href-works-only-after-clearing-browser-cache-on-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!