Ember App Cannot Load Json Data From Local File
Solution 1:
Ember comes with Development server(localhost:4200) and it can't be used like a webserver and it can't be used to response ajax request. You can't make this work Ember.$.getJSON("/products.json")
with localhost:4200 endpoint.
You need backend any webserver to return response. If you don't have that at present then for development purpose, you need to work with dynamic render data, then I prefer to use ember-cli-mirage addon.
Solution 2:
What about placing the JSON in the app folder and importing it?
import Ember from 'ember';
import yourData from 'your-app/json-file-name.js';
export default Ember.Route.extend({
model() {
return yourData;
}
});
https://ember-twiddle.com/afb9d71933322860938b3936d617a776 - you can use this to try and get a .json working...
There is a thread here too: https://discuss.emberjs.com/t/how-to-import-data-from-json-file-to-ember-app
BUT... don't expect it to properly be in the ember-data store - and function like you'd expect in many situations.
Post a Comment for "Ember App Cannot Load Json Data From Local File"