【发布时间】:2013-03-20 15:52:26
【问题描述】:
我正在使用 require.js 文本插件 (https://github.com/requirejs/text) 从服务器加载我的 html 模块。
服务器有另一个主机,因此通过在 require.config 对象中使用 Xhr 来允许 coss-domain-request。
text: {
useXhr: function (url, protocol, hostname, port) {
// allow cross-domain requests
// remote server allows CORS
return true;
}
},
但是当我加载某个模块时,浏览器会尝试将加载的文件解释为 javascript 文件。
define([
'text!/view_templates/header.html'], function(html){
console.log(html)
})
在broser一个get:
资源解释为脚本但以 MIME 类型传输 文本/html: “http://app-id.appspot.com/gadget/js/app/view_templates/header.html”。 require.js:1843 Uncaught SyntaxError: Unexpected token
有人知道问题出在哪里吗?
感谢帮助
【问题讨论】:
-
我发现覆盖 useXhr 方法不起作用。所以在插件self中修改函数
标签: javascript cross-domain requirejs requirejs-text