1

They will blocked constantly to cross origin issues. I know, they can't be load from remote by default wihtout extra config, but this is absurd and make no sense! And I don't want to attach them within main.html code, because they are so many and some are very large.

First thought, there's something to do being originally copied from another domain, but it throws same cross origin error, what ever non-existing starting with "text!templates/..." you trying, whithout even getting that far to error about not finding a file.

Code:

<script src="https://cdnjs.cloudflare.com/ajax/libs/require-jquery/0.25.0/require-jquery.js"></script> 

require.config({
   config: {
     text: {
        useXhr: function (url, protocol, hostname, port) {
           return true;
        }
     }
   };
   paths: {
     jquery:"http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js",
     underscore: "underscore",
     text: "libs/text",
     backbone: "http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min",
     marionette: "http://cdnjs.cloudflare.com/ajax/libs/backbone.marionette/2.2.1/backbone.marionette.min"
  )
});

require(["App","jquery", "underscore", "backbone", "marionette","text!templates/basket/basket.html"], function(App,$,_,Backbone,Marionette,template){

Resulting(in Firefox+ Chrome):

GET http://myhost.../templates/basket/basket.html 302 FOUND (message with RED colour)
GET http://error.myhost/? 200 OK (with black)
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://error.myhost.../?. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

Trying to change useXhr: function (url, protocol, hostname, port), but don't know the right syntax, is it (url:"my URL", protocol:'my host protocol'.. port:XX) or should they leave as it is? But again, what's the point of changing, if they are in my host server? Am I missunderstood something? Anybody can give any hint?

Thank's in advance!

1 Answer 1

0

Your require.config looks good to me with respect to the text plugin.

I'm pretty sure your problem is on the server side. You need to make sure that the server is sending the Access-Control-Allow-Origin property to your domain of origin.

Before you require that text, please try adding:

$.support.cors = true;

This may "force" it to work, although I'm not 100% sure. Try that if you don't want to mess with the server at the moment but do fix the problem on the server by adding CORS support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.