只有在Chrome中打开开发人员工具后,Javascript才起作用 [英] Javascript only works after opening developer tools in chrome

查看:185
本文介绍了只有在Chrome中打开开发人员工具后,Javascript才起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和这里有同样的问题:

I have the same problem as in here:

为什么JavaScript仅在打开后才起作用一次在IE中使用开发人员工具?

除了我的是铬44.

JavaScript代码-主要是XHR和setInterval- 完美运行-开发人员工具打开时

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

(只能是XHR问题)

这是一个网络应用程序-即:一个宽度为300px的弹出式寡妇,位于用户当前正在处理的内容旁边.

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.

此处的解决方案: 如果chrome,AJAX可以使用开发工具可以打开,但是如果chrome网络工具可以关闭吗?

似乎不适用-因为我正在使用动态文件的帖子

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

任何想法:-)?

@michaelAdam启发-大多数问题是缓存问题,因为我使用了很多XHR'get'(未缓存) 嗯..有趣的是: 使用:

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 });

似乎并没有解决问题. 添加: @Mattisdada:

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)

防止Chrome浏览器缓存AJAX请求

似乎可以解决问题-到目前为止...

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

推荐答案

您需要为jQuery AJAX创建cache: false,以便响应数据不会被缓存在浏览器中.另一个技巧也是(如果有人不使用jQuery),通过发送一些唯一值作为参数(例如new Date().getTime()).

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()).

示例:

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

这篇关于只有在Chrome中打开开发人员工具后,Javascript才起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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