I just started learning about jQuery Deferred, but I think I understood in theory. When trying to use them in a script, I have the feeling I am misusing them. Take this example:
var dataA = $.get('http://www.example.com');
dataA.done(function (result) {
var dataB = $.get('http://www.example.com?name='+result.name);
dataB.done(function(result) {
console.log('Data fetch successful: ' + result)
});
});
dataB
depends on the outcome of dataA
, so some kind of execution order has to be preserved. Am I using the done
callbacks correct is this example?
To me it still feels like regular "callback hell" because I declare dataB
inside dataA.done
, so is suspect there is a more idiomatic way.