when().then() pattern in the following situation:
$.when(setServerValue("true"))
.then(function(){
console.log('done setting new value');
performSomeOperation();
})
.fail(function(){
alert('server value not set!');
});
var setServerValue = function(newValue){
return $.post('http://myURL',{key:newValue});
};
The problem here is that the 'then' or 'fail' operations are never called using a $.post() operation. I've successfully used this approach with $.get() operations, and if I understand the API docs correctly (apparently not), this should also work for $.post operations.
Can anybody help me with this? Thanks!
The problem is that setServerValue is not defined as function when you call it. Move your definition of setServerValue above the $.when call.
Working example: http://jsfiddle.net/petersendidit/JHkKG/