Assigning value to a variable from ajax call in ember.js
ajax, ember.js, javascript, jquery
Solution
The proper way to set up a route is like this, if you want to check out the value you would do this in the afterModel hook.
App.ExamplesRoute = Ember.Route.extend({
model: function() {
return $.post("/Example/GetExamples");
}
afterModel: function(model) {
console.log(model);
}
});
Problem
I am trying to assign value to a variable with json(returned from server side). I don't want to use ember-data for managing models and defining a RestAdapter as it is still in beta. ``` App.ExamplesRoute = Ember.Route.extend({ beforeModel: function() { var request = $.post("/Example/GetExamples"); request.then(this.success.bind(this), this.failure.bind(this)); }, success: function(data) { var examples=data; alert(example); if(examples==null){ alert('examples are null'); } }, failure: function() { alert('failed'); }, model: function() { return examples; } }); ``` Basically I am trying to assign a value to examples variable from a json object. The problem is that I get a javascript error saying examples is not defined in model: function() { return examples; } }); So what would be the correct way to do this?