我有一些非常基本的 RequireJs 代码,可以使用简单的 html 获取 html 文件。
在 Firefox 8.0 中它工作正常,但是在我的 Chrome (17.0.9.xxx) 版本中,我收到以下错误:
Cross origin requests are only supported for HTTP.
这可能只是 Chrome 版本或一般文本插件的问题吗?
define([
'jquery',
'backbone',
'text!templates/home/listOfStuff.html'
], function ($, Backbone, mainTemplate) {
var mainView = Backbone.View.extend({
el: $('#list'),
render: function () {
this.el.html(mainTemplate);
}
});
// return the view object
return new mainView;
});
当 Require 尝试获取 html 文件时,就会发生错误。
最佳答案
这是 chrome 的本地文件系统访问策略。对于本地开发,您只需添加以下标志:
--allow-file-access-from-files --disable-web-security
关于backbone.js - RequireJs 文本插件在 Chrome 中出现跨源错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8408031/