0

Im using Ember and Ember-Model to develop a front end which is calling a Spring/Rest/MongoDB back end, which is all running on my local machine for development purposes, but I get the same origin policy error for my call.

I want to know what the common work around for this is.

Here is my code:

App = Ember.Application.create();

App.Router.map(function(){

});

App.IndexRoute = Ember.Route.extend({
   model: function(){
       return App.User.find();
   }
});

App.User = Ember.Model.extend({
    lastName: Ember.attr()
});

App.User.adapter = Ember.Adapter.create({
    findAll: function(klass, records) {
        $.getJSONP("http://localhost:8080/users").then(function(data) {
            records.load(klass, data.users);
        });
    }
})
Peter S
  • 351
  • 1
  • 3
  • 13
  • If you call $.getJSONP("users") instead do you get the same error? – bhspencer Feb 07 '15 at 20:16
  • The @.getJSONP actually doesnt work at all. I think perhaps it doesnt exist in Ember (or is this a JQuery thing? I have no idea). It was my attempt to solve the problem. So the actual call is $.getJSON. I've tried this: "/users" and it was looked for "file:///C:/users" and I even created a JSON file called users.json and then tried: "/users.json" and this also failed. :( – Peter S Feb 08 '15 at 02:05

1 Answers1

0

The same origin policy on localhost is the same as on the rest of the web. However, if you open your web app as a file (ie. the address starts with file:/// every other uri, even those of other files, will have a different origin.

To solve this, serve your app from a server running on your own machine, than look at it by going to http://localhost.

bigblind
  • 12,539
  • 14
  • 68
  • 123
  • That's a fantastic solution, however, I am trying that now but having problems determining where Spring Boot is exactly running from. I have my html file here: "C:\Users\Me\Google Drive\workspace-sts-3.6.0.M1\BookingSoftware2\html\index.html" and my Spring Project is in BookingSoftware2. So where is the localhost directory? – Peter S Feb 07 '15 at 21:00
  • 1
    There's no localhost directory. localhost is the 'domain name' that is mapped to your own computer. To access your app this way, there has to be some server running that serves it to the browser. I hear great things about [mongoose](https://code.google.com/p/mongoose/) for serving static files on Windows. – bigblind Feb 07 '15 at 21:32
  • Yes I know this. That is why I mentioned Spring Boot. With Spring boot the webserver is tomcat and it lives in the jar file created by Spring. So this means that its not "installed" on my local machine until deployment of the jar. This is the process that I dont understand: When it is deployed what folder does it make available to host the web server files (if any). – Peter S Feb 08 '15 at 02:02