0

I've got a simple rest service which provides a Route in my Ember app with some basic model data.

Here is my attempt to make it available:

model: function () {
    var promise = new Em.RSVP.Promise (function (resolve, reject) {
      var request = new XMLHttpRequest();
      request.open("GET", "https://myStupidService/bla");
      request.onreadystatechange = handler;
      request.setRequestHeader("Accept", "application/json");
      request.setRequestHeader("Authorization", authHeader);
      request.send();
      function handler () {
        if (this.readyState === this.DONE) {
          if (this.status === 200) {
            resolve(this.response);
          } else {
            reject(this);
          }
        }
      }
    });
    return promise;
}

When I mock the resolve method like this ...

// ...
if (this.status === 200) {
    resolve({testProp: "RESOLVED"});
} else {
// ...

... testProp can be rendered.

I also know that there are no errors in the template and that the promise _data prop contains everything needed when logged.

After several different, non-working variations (also tried jquery) I think its time for some insight.

Thanks in advance!

Doe Johnson
  • 1,374
  • 13
  • 34
  • What's the response from server look like? Is it just a string? – Kingpin2k Oct 20 '14 at 14:47
  • Yea, The problem actually was the (malformed) server response. Too bad you dont get meaningful error messages. Maybe I should delete the question. – Doe Johnson Oct 20 '14 at 14:52
  • I would agree with you on the meaningful error messages, but probably not in the way you mean it. I'd say either XMLHttpRequest or jQuery might give you a more meaningful error message since they are in the business of ajax calls, whereas Ember itself, doesn't deal with this. A string, an object etc all can legally be used as a model for ember. – Kingpin2k Oct 20 '14 at 23:21

0 Answers0