I have a task to perform Ajax calls for each item in an array and then trigger another function once all the calls are completed.
Adding complexity, I am incorporating Papa Parse into making the Ajax call.
This is the code snippet:
getCsvData: function(url) {
var _this = thisl
Papa.parse(url, {
download: true,
complete: function(data) {
return data;
}
});
},
getBackendData: function() {
var _this = this;
var results = {};
_this.numeratorIds.forEach(function(d) {
var url = _this.constructUrl(d.id, d.query_type);
results[url] = _this.getCsvData(url);
});
// Perform tasks when everything is finished...
// invoke another function to render the final data.
},
I'm uncertain if this approach is optimal - do you recommend a better method?
Note: While it may be slower to make multiple Ajax calls rather than chaining URL parameters for a single call, I believe it's appropriate in my scenario. Working with a large, static database warrants caching these queries more frequently.