I'm currently working on a solution for chaining 3 ajax calls where the result of one call feeds into the next two. Here's the scenario:
// Invoke the ajax calls
firstAjax('mypage.gng','john-doe').then(secondAjax, thirdAjax).done(function(second_ajax_data, third_ajax-data) {
console.log(second_ajax_data);
console.log(third_ajax-data);
});
// Define our ajax calls
const firstAjax = function(urlAjax, userName) {
return $.ajax({
url: urlAjax,
type: 'POST',
data: userName
)};
const secondAjax = function(sessionId) {
return $.ajax({
url: '/userLogins/getUserLogins',
type: 'POST',
data: sessionId
)};
const thirdAjax = function(sessionId) {
return $.ajax({
url: '/userHistory/getUserHistory',
type: 'POST',
data: sessionId
)};
Essentially, the firstAjax call fetches the sessionId and then passes it to the other 2 ajax calls simultaneously. However, I'm facing issues in obtaining the data returned by the last two calls using the above setup. I would really appreciate any assistance.