QUESTION
I call a function from an extended javascript object, which returns a deferred object.
My code looks like this
XModel.prototype = new Model();
function XModel()
{
this.load = function()
{
var url = 'php/main.php?controller=data&action=load';
// would like to have the data here
this.getServer().get(url).done(function (data) {
// i wanna pass this data back to the controller object,
// outside this XModel object
}).fail(function(textStatus) {
throw (textStatus.responseText);
});
}
}
Now I cannot manage to return the data to the controller object which calls mXModel.load(); neither to pass it inside function load of XModel object.
Thanks for help
SOLUTION
If you would like to return the data, because of your MVC Model the solution is...
function Controller()
{
this.load = function()
{
var mXModel = new XModel();
mXModel.load().done(function(data) {
var mXView = new XView(); // create new View Object
mXView.show(data); // call function show and pass the data
}).fail(function(error) {
// some error code
});
}
}
I wanted to return the data from the XModel to the Controller because I create a XView object only in the Controller and not the XModel.
So this is like you would return the data. You call the load function in the Controller, and when it is finished (done), the code will be executed.
Hope it helps :)
Maybe not duplicate cause of the possible solution?