在FF和所有,我的javascript工作良好。但在Chrome中,它会给出这样的信息:

资源解释为脚本,但传输与MIME类型文本/纯。

我已经检查了所有的脚本标签,他们都有MIME类型=“文本/javascript”。它甚至说jquery和jquery ui。Chrome出了什么问题?

问题是什么,解决方法是什么?它是我必须改变浏览器的“选项”,还是来自服务器,或者我必须调整我的代码?


当前回答

如果你正在使用AdonisJS (REST API,例如),一种避免这种情况的方法是这样定义响应头:

response.safeHeader('Content-type', 'application/json')

其他回答

simon-sarris在这里发布的答案帮助了我。

This helped me solve my issue. The Visual Studio installer must have added an errant line to the registry. open up regedit and take a look at this registry key: See that key? The Content Type key? change its value from text/plain to text/javascript. Finally chrome can breathe easy again. I should note that neither Content Type nor PercievedType are there by default on Windows 7, so you could probably safely delete them both, but the minimum you need to do is that edit. Anyway I hope this fixes it for you too!

更改后不要忘记重新启动系统。

对我来说,它只发生在一些页面上,因为我使用了window。Location代替$ Location .url(…);这解决了我的问题。花了一段时间才弄明白:)

如果您正在使用Joomla!并且在尝试包含(.js) JavaScript文件时得到这个恼人的错误,那么下面的解决方案适合你。

最可能的问题是您试图包含一个不存在的.js文件,或者您只是放错了那个.js文件,而当Joomla!如果没有找到资源,那么它将返回一个完整的404消息,其中包含完整的网页和HTML等。

web浏览器将它解释为.js,而它只是一个网页,说所需的文件没有找到。

这可以为joomla2.5joomla3.0joomla3.1joomla3.2joomla3.3joomla工作

当我试图通过javascript (jQuery在这种情况下)改变数组中的背景图像时,我也遇到了同样的问题。

无论如何。

而不是这样:

m.setStyle('background-image','url(/templates/site/images/style5/'+backgs[i]+')')

这样做:

eval("m.setStyle('background-image','url(/templates/site/images/style5/'+backgs[i]+')')");

Chrome javascript在试图解析一个以'为结构的元素中的变量时会搞砸。在我的例子中,它在插入图像数组之前停止。它不是解析图像url +图像名称(在数组内),而是只解析图像url。

您可能需要在代码中搜索,看看它发生在哪里。FF, IE和其他所有的都没有这个问题。

在apache的httpd.conf中,只需添加这样一行:

AddType application/x-javascript .js