Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequireJs text plugin gives Cross origin error in Chrome

I have some very basic RequireJs code that fetches an html file with simple html. In Firefox 8.0 it works fine, however in my build of Chrome (17.0.9.xxx) I get the following error:

Cross origin requests are only supported for HTTP.

Could this just be a problem with this build of Chrome or the text plugin in general?

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;

});

When Require attempts to fetch the html file is when the error occurs.

like image 550
Mike Fielden Avatar asked Dec 06 '11 22:12

Mike Fielden


2 Answers

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

like image 77
Ugnius Avatar answered Nov 03 '22 00:11

Ugnius


I agree with ProTom there, if you set up a webserver to serve up your html pages you should be all set.

like image 37
Collin Estes Avatar answered Nov 02 '22 23:11

Collin Estes