使用require.js文本插件(https://github.com/requirejs/text)從服務器加載我的html模塊。requirejs文本插件將腳本解釋爲腳本
服務器有另一個主機,所以通過在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:
Resource interpreted as Script but transferred with MIME type text/html: " http://app-id.appspot.com/gadget/js/app/view_templates/header.html ". require.js:1843 Uncaught SyntaxError: Unexpected token < header.html:1
有沒有人有任何想法問題出在哪裏?
感謝您的幫助
我發現重寫useXhr方法不起作用。所以一個修改插件自身的功能 –