I have a Flask Python Server using a CeleryOnce worker to collect and format some data based on a query from the user. I have a page, created with the EmberJS CLI 2.5, which needs to send that query to my Flask server as well as poll my server to retrieve the current status of the CeleryOnce worker. My main point here is that I'm using the default generated files from the EmberJS CLI, but I'm not using the default Ember CLI Data source.
Can somebody point me in the right direction of how I update my ember js page with the data pulled from an ajax query? Or perhaps have my controllers poll the data and pass it into the component without refreshing the page? It looks like Ember-Data assumes the server and pages are on the same port/URL/machine, but that isn't the case in my situation. (Or should it be?)
I have all the building blocks set up in my EmberJs project, and I have all the data able to be served as JSON on my Flask project, but I just can't seem to connect the two together.
Sadly, my google searches have all resulted in old versions of EmberJS which no longer seem to work with the current version.
Though I accepted the answer, I had to make a modification to set the var properly:
request() {
var comp = this;
Ember.$.getJSON('http://localhost:5000/api/v1.0/', 'GET').then(function(tasks) {
comp.set('tasks',tasks);
});
Can somebody point me in the right direction of how I can periodically make calls to my python server from my ember js page to pull the data like an ajax query?
It's worth saying that polling is a network / data / model layer concern-- how you poll should not be coupled to your template, or how you display the data on the page.
Ember provides some built-in APIs that can help with polling. Aside from that, polling a server in Ember is no different than in any other Javascript app. Any kind of polling solution is ultimately going to involve making AJAX requests at different times, on some kind of schedule.
I'd recommend starting with Ember.run.later. If you're feeling more ambitious, you could check out the Ember Concurrency addon as well.
The simplest solution probably looks something like this:
import Ember from 'ember';
export default Ember.Component.extend({ // Or Ember.Controller.extend({ ...
setupPolling: Ember.on('init', function() {
this.pollRequest();
}),
pollRequest() {
this.request();
Ember.run.later(this, this.pollRequest, 100);
},
request() {
// Do your AJAX / Ember Data call here. Set the results of the call on your Component so you can render it in your template. The template will update automatically when the data changes.
},
});
You have a few different questions embedded in your answer (e.g. about CORS). Try to break these out into separate questions-- it makes them a lot easier for other SO users to respond to, and you'll get better answer rates as well. Also, try not to make your question overly specific. If you want to learn about polling in Ember, there's probably no need to specify what kind of server you're using on the backend.