I'd like to know how to make dependent AJAX calls using promises/deferred from jQuery. Right now I have something like this:
$.when($.ajax('https://somedomain.com/getuserinfo/results.jsonp', {
dataType : 'jsonp',
jsonp : true,
jsonpCallback : 'userCallback'
}))
.then(function (data) {
return $.when($.getJSON('http://www.otherdomain.com/user/' + data.userId), $.getJSON('http://www.anotherdomain/user').then(function (json1, json2) {
return {
json1 : json1,
json2 : json2
};
});
});
It's working for me as expected, but I don't know whether it is a correct way of doing this. Do you have any suggestions on how to improve that?