Javascript only works after opening developer tools in chrome

陌路散爱 提交于 2019-12-12 01:19:27

问题


I have the same problem as in here:

Why does JavaScript only work after opening developer tools in IE once?

except that mine is with chrome 44.

JavaScript code - mainly XHR and setInterval - works perfectly - when the developers tools are open

(could be only XHR issue)

This is a web app - i.e: a pop up widow, 300px in width, that is stationed next to whatever the user is currently working on.

the solution here: AJAX works if chrome dev tools open but not if chrome web tools closed?

does not seem to apply - since I'm using post for dynamic files

any ideas :-) ?

EDIT: as @michaelAdam enlighted - most of the problems are caching issues as I used quite a lot of XHR 'get' (which is not cached) hmm.. interesting to note: using:

$.ajaxSetup({ cache: false });

did not seem to do the trick. adding: @Mattisdada:

header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");//Dont cache
header("Pragma: no-cache");//Dont cache
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");//Make sure it expired in the past (this can be overkill)

Prevent Chrome from caching AJAX requests

did seem to do the trick - so far...


回答1:


You need to make cache: false for jQuery AJAX, so that the response data won't be cached at browser. Another trick is too (if somebody is not using jQuery) make the URL unique by sending some unique value as parameter (like new Date().getTime()).

Example:

$.ajax({
    url: 'http://someurl', 
    cache: false, 


来源:https://stackoverflow.com/questions/31918035/javascript-only-works-after-opening-developer-tools-in-chrome

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