【问题标题】:Select2 mimetype errorSelect2 mimetype 错误
【发布时间】:2017-07-15 17:31:30
【问题描述】:

我正在尝试使用 Select2,但 Chrome 拒绝执行脚本,因为 mimetype 是 text/html。我正在使用 4.0.3。这是我的html:

<link href="static/js/common/select2/css/select2.min.css" rel="stylesheet" />
<script src="static/js/common/select2/js/select2.js"></script>
<script src="static/js/controllers/common/SelectAgency.js"></script>

<select id="auto"></select>

SelectAgency.js 的代码是这样的:

var data = [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }, { id: 3, text: 'invalid' }, { id: 4, text: 'wontfix' }];

$("#auto").select2({
 placeholder:'Test'
})

选择框出现,但它不包含任何内容。此消息也会出现在控制台中

select2.min.js:233 资源解释为样式表,但使用 MIME 类型 text/html 传输:“http://localhost:8080/foiaonline/action/public/request/static/js/common/select2/js/static/js/controllers/common/select2/css/select2.min.css”。

【问题讨论】:

  • 该消息不是由您在代码中编写的任何内容引起的,而是因为您托管文件的方式。您使用什么应用程序来托管 .js 文件?
  • 我已将其本地存储在我的 Eclipse 项目中
  • this 可能是您收到的警告的解决方案。不过,我不确定这是否能解决选择框问题。

标签: javascript css


【解决方案1】:

我使用的是旧版本的 select2(3.5.1)。在 3.5.1 中,select2 被初始化为:

$(panel).select2({
    placeholder:placeholderStr,
    data: items
});

<input id="panel" type="text", class="auto"/></td>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-21
    • 2011-03-23
    • 1970-01-01
    • 2015-07-25
    • 1970-01-01
    • 2018-08-09
    • 2015-08-09
    • 2018-10-18
    相关资源
    最近更新 更多