javascript - 脚本被解释为样式表,但以 MIME 类型 text/html 传输

标签 javascript php html .htaccess mime-types

我在 Chrome 中收到两个控制台警告:

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://domain/". domain/:11
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://domain/". domain/:11

在第 11 行,我有:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> 

这是 head 部分的所有代码:

<head>
<meta charset="UTF-8">
<title>Laoautod</title>

<meta http-equiv = "Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/base.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> 
<script type="text/javascript" src="js/center.js"></script>
<script type="text/javascript">
    function displayResult()
                    {
        var x=document.getElementById("checkbox").defaultChecked;
        alert(x);
                    }
</script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'accountID']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>

HTML 代码位于 index.php 文件内,因此我在页面脚本的开头添加了 header('Content-type: text/css'); 。我还在 .htaccess 文件中添加了 AddCharset utf-8 .css .jsAddType text/css .css ,但没有丢失警告.

到底是什么原因造成的?如何消除这些警告?

最佳答案

好的,我发现问题了。

我收到警告的原因是因为我在 base.css 中使用 @import 引入不在其位置的脚本。准确地说,我缺少 2 个脚本,所以大概这就是我收到 2 个警告的原因。

关于javascript - 脚本被解释为样式表,但以 MIME 类型 text/html 传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22221147/

相关文章:

javascript - Angular 上的关注点分离,何时使用服务和/或工厂?

javascript - Angular ngOptions 前置字符串 : to value

javascript - 使用 JavaScript 覆盖/删除 CSS 属性

php - 如何从子 ID 获取父 ID(根父)

php - 在 php : class not found 中使用库

javascript - 如何在我的变量中使用本地存储值?

jquery - Bootstrap 3 : How to close popup using jQuery?

javascript - 通过 AJAX 和 PHP 通过输入 HTML 获取和读取文件

javascript - 如果在数组中找到特定单词则运行函数

php - 重定向 index.php 不会在 PHP url 参数中加载带有斜杠的 css