Error while loading route

I have a Group model that is pulling a json feed into an array and then its suppose to render it to the groups template.

My model looks like this:

Mdm.Group = Ember.Object.extend(); // Creating new model class

Mdm.Group.reopenClass({
   all: function() {
   return $.getJSON("http://localhost:3000/1/organizations/1/groups?format=jsonp&callback=?").then(function(response) {
    var groups = [];

    response.groups.forEach( function (group) {
        groups.push(Mdm.Group.create(group));
    });
    return groups;
    });
  }
});

And my GroupsRoute:

 Mdm.GroupsRoute = Ember.Route.extend({
    model: function() {
       return Mdm.Group.all();
    }
});

The application is retrieving the json. The network tab in inspector loads every record perfectly, its just not spitting it back out.

In the console I get the following errors:

Uncaught SyntaxError: Unexpected token : groups:1
  Error while loading route: 
  Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}
  application.js:12147
  (anonymous function) application.js:12147
  Ember.Router.reopenClass.defaultFailureHandler.setup application.js:36146
  failure application.js:35559
  (anonymous function) application.js:35621
  (anonymous function) application.js:1193
  fire application.js:1038
  self.fireWith application.js:1149
  (anonymous function) application.js:1200
  fire application.js:1038
  self.fireWith application.js:1149
  (anonymous function) application.js:1200
  fire application.js:1038
  self.fireWith application.js:1149
  done application.js:8077
  script.onload.script.onreadystatechange application.js:8330
  Uncaught #<Object> application.js:36149
 (anonymous function)

I know most of that is meaningless but if anyone has ever seen this before I’d appreciate any feedback.

2 Likes

Was a json issue the whole time.

Model code should be:

   response.response.forEach( function (group) {

I am facing the same issue that you mention here and cannot think of any solution. I have a couple of questions about your solution:

  1. What is the second response in response.response.forEach supposed to denote?
  2. Can you post a sample of the json that you were trying to render?