Below is my code. The first console message shows result, the second one doesn't... Doesn't this magically break promises... how is this possible?
this.saveAsTemplate = function(name, asNew) {
return _saveSet(name, asNew)
.then(function(result) {
// -> result is set correctly
console.log('oh but youll ****ing work... wth?', result);
$.ajax({
url: '/rest/filter/template/'+result.id,
type: 'PUT',
}).success(function(result) {
console.log('successfully saved template, result: ', result);
});
})
.then(function(result) {
// -> result is undefined :(
console.log('no ****ing result: ', result);
});
For the last few months I've been having to write additional deferreds just to get around this issue... it's really messing with my code. Help would be greatly appreciated!
EDIT: A good clear example solution of chaining promises properly can be found in this question: (notice everything function returns) How do I chain three asynchronous calls using jQuery promises?