I calling multiple API endpoint within ember router model I'm using ember-cli 3.11.0 When I refresh the page, it failed to load with "Uncaught (in promise)" which point specifically in $.ajax call
import $ from 'jquery';
import { hash } from 'rsvp';
export default Route.extend(AuthenticatedRouteMixin, {
model: function (param) {
return hash({
category: $.ajax({
url: 'http://localhost:8000/catalog/category/' + param.id,
type: 'GET'
}).then(function(res) {
return res;
}),
categories: $.ajax({
url: 'http://localhost:8000/catalog/category',
type: 'GET'
}).then(function(res) {
return res;
})
})
}
});
With those codes, I want to call inside setupController something like
setupController(ctrl, model) {
console.log(model.category);
console.log(model.categories);
}
ember-ajax
, which is part of Ember's default blueprint? Isn't there any information about the error that wasn't catched? If so, you should catch and log the error to gather additional information. What is the result of the network requests? If it's not returning a200
or isn't valid json but including aContent-Type: application/json
headerjQuery.ajax()
will throw. I would recommend usingfetch
instead ofjQuery.ajax()
for new applications. – jelhan