1

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.

Kishor Pawar
  • 3,386
  • 3
  • 28
  • 61

2 Answers2

0

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: enter image description here

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: enter image description here

Hans Yulian
  • 1,080
  • 8
  • 26
  • Hans how will this help me? Please read and understand question again. – Kishor Pawar Nov 16 '16 at 10:53
  • Because when developing, browser might still caching the assets, that's why if you clear cache or opening debugger/developer tools, you can proceed, because usually developer tools will have the option to disable caching. this wont help you, but you might have additional info about how browser work. remember that when they make browser, they will aim for consumer, which we can assume have less knowledge about caching and so on, so you expect them to enable caching by default, and provide disable cache in developer mode. opening the developer tools is like telling you are developer – Hans Yulian Nov 16 '16 at 10:57
  • i want to tell that in developer mode, there is an option that disable cache to help you understand of "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." and yes most likely you, me, and other developer need to open developer tool when developing in CSS and JS, especially when we already using webserver, instead of file base. – Hans Yulian Nov 16 '16 at 10:58
  • Hans I have updated a Post and added a real question. Thanks for your time though. – Kishor Pawar Nov 16 '16 at 11:01
  • try this one, this might disable the cache – Hans Yulian Nov 16 '16 at 11:04
  • Hans I can't keep asking consumer of my application to do that, as you said they might have less knowledge about how browsers work. – Kishor Pawar Nov 16 '16 at 11:06
  • Is this happened in production environment or you are still in development? if already happened in production environment, so sorry i can't help with this, but if you are still in development, you can just ignore this problem. – Hans Yulian Nov 16 '16 at 11:11
  • This is happening on staging/testing server, and I am debugging on development machine. – Kishor Pawar Nov 16 '16 at 11:13
  • may i know what is the web server used for this? nginx, iis, or apache? – Hans Yulian Nov 16 '16 at 11:15
  • can you try "Cache-Control: no-cache" http://nginx.org/en/docs/http/ngx_http_headers_module.html – Hans Yulian Nov 16 '16 at 11:16
0

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.

Community
  • 1
  • 1
Kishor Pawar
  • 3,386
  • 3
  • 28
  • 61