Handling several asynchronous ajax calls in a specific order with information passing between them can be quite challenging. The current approach, even with just three API calls, can be cumbersome. Trying to manage five API calls makes it nearly impossible to organize the error workflow or adjust functions effectively due to limited screen space. Is there a more efficient way to achieve the desired outcome?
/*
* API Call to get user
*/
$.ajax({
type: 'POST',
url: `robin.hood/get_user`,
data: JSON.stringify({"name":"Joe Dirt"}),
headers: {Authorization: 'Bearer ' + token},
datatype: 'json',
contentType: 'application/json; charset=utf-8',
success: function (data, text_status, jq_xhr) {
/*
* Assume one user is returned only
*/
let user_id = data;
// Additional nested AJAX calls and operations...
});
For similar questions:
- Chaining multiple jQuery ajax requests
- jquery how to use multiple ajax calls one after the end of the other