I have to methods, that return promises. And I want to make second method to be executed after first would get and manipulate data. This question has being asked several times, still cannot find a way to make it work. Here is my code:
self.getSpesialitet = function () {
console.log("Starting Spesialitet");
return $.get(options.getSpesialitetUrl, { 'recno': recno }, function (data) {
////Code
console.log("Success Spesialitet");
});
};
self.getVedtak = function () {
console.log("Starting Vedtak");
return $.get(options.getVedtakUrl, { 'recno': recno }, function (data) {
////Code
console.log("Success Vedtak");
});
};
$.when(self.getSpesialitet()).then(self.getVedtak()).then(console.log("Everything is done"));
And here is the result witch I get:
Starting Vedtak
Starting Spesialitet
Everything is done
Success Vedtak
Success Spesialitet
And the result I would like to get:
Starting Vedtak
Success Vedtak
Starting Spesialitet
Success Spesialitet
Everything is done