Select2 mimetype错误
问题描述:
我想使用Select2和Chrome拒绝执行脚本,因为mimetype是text/html。我正在使用4.0.3。这里是我的html:Select2 mimetype错误
<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”传输。
答
我使用的是旧版本的select2(3.5.1)。在3.5.1中select2被初始化为:
$(panel).select2({
placeholder:placeholderStr,
data: items
});
<input id="panel" type="text", class="auto"/></td>
该消息不是由您在代码中编写的任何内容引起的,这是因为您托管该文件的方式。您使用什么应用程序来托管.js文件? – Jespertheend
我把它存储在本地的日食项目 – Hardrock302
[this](http://stackoverflow.com/questions/11480347/js-and-css-files-areloading-as-text-html-in-my-jsp页面)可能是你得到的警告的解决方案。我不确定这是否会解决选择框问题。 – Jespertheend