RequireJs text plugin gives Cross origin error in Chrome
-
29-10-2019 - |
سؤال
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.
المحلول
I agree with ProTom there, if you set up a webserver to serve up your html pages you should be all set.
نصائح أخرى
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
لا تنتمي إلى StackOverflow