5

我有一些非常基本的 RequireJs 代码,可以使用简单的 html 获取 html 文件。在 Firefox 8.0 中它运行良好,但是在我构建的 Chrome (17.0.9.xxx) 中我收到以下错误:

仅 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 文件时,就会发生错误。

4

2 回答 2

9

It's chrome's local file system access policy. For local development you could just add following flags:

--allow-file-access-from-files --disable-web-security

于 2012-04-27T09:30:19.787 回答
5

我同意 ProTom 的观点,如果您设置了一个网络服务器来提供您的 html 页面,那么您应该一切就绪。

于 2011-12-07T19:36:48.330 回答