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

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

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

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


当前回答

我有同样的错误,最后(在我的特殊情况下),我发现部署描述符(web.xml)有问题

存在的问题:

<servlet-mapping>
    <servlet-name>SessionController</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
...
<welcome-file-list>
    <welcome-file>/</welcome-file>
</welcome-file-list>

解决方案:

<servlet-mapping>
    <servlet-name>SessionController</servlet-name>
    <url-pattern>/SessionController</url-pattern>
</servlet-mapping>
...
<welcome-file-list>
    <welcome-file>desktop.jsp</welcome-file>
</welcome-file-list>

其他回答

我遇到了这个问题,我找到了解决它的方法。

当样式(CSS)文件的编码与引用.css文件的PHP文件的编码不同时,就会发生这种情况

例如,使用Unix编码的jQuery.js和使用UTF-8编码的index.php会导致这个问题,所以你必须让它们都是UTF-8或任何其他编码,只要它们是相同的。

检查你的js文件是否在服务器上存在。我有这个问题,发现js文件没有上传到服务器,服务器实际上是返回html页面,而不是-这是服务器上配置的默认文档(如default.html)

如果你用一个php文件生成javascript,添加这个作为你的文件的开头:

<?php Header("Content-Type: application/x-javascript; charset=UTF-8"); ?>

对于Java应用服务器,如Weblogic

1)确保你的weblogic.xml文件没有错误

比如这个:

    <?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd"
                  xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
    <container-descriptor>
        <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>
    <context-root>MyWebApp</context-root>
</weblogic-web-app>

2)在web.xml文件中添加javascript的mime类型:

    ...
        </servlet-mapping>

        <mime-mapping>    
            <extension>js</extension>        
            <mime-type>application/javascript</mime-type>        
        </mime-mapping>

        <welcome-file-list>
    ...

这也将适用于其他Java容器- Tomcat等应用程序/javascript是目前唯一有效的mime类型;其他如text/javascript已弃用。

3)您可能需要清除浏览器缓存或按CTRL-F5

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!

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