How about making an Ajax request for each item in the array?

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.

Answer №1

Have you considered having the controller return a List of objects instead of making multiple AJAX calls? By doing this, you can eliminate the need for multiple calls and instead just make one Ajax call to retrieve the list of objects you need. This way, you can easily bind the data to your views without the hassle of multiple requests.

I hope this solution makes sense to you.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Conceal an element from view upon clicking on it

Task at Hand : Implement a smooth element hiding effect upon clicking, similar to the behavior on this website , where the letter A fades away smoothly when clicked. Is it possible to achieve this effect using only HTML, CSS, and JavaScript? var t ...

Create div elements using JSX and add them to an array

I am working with a structure that looks like this: var circle = { 'one': {items: []}, 'two': {items: []}, 'three': {items: []}, 'four': {items: []} }; Each items array needs to contain 10 unique ...

The function will not be triggered when the form is submitted

I've set up this form to send data to the server-side. It's built in HTML/CSS with AngularJS as well. I made sure that the button is placed inside the form, a common mistake that can cause issues. However, despite my efforts, the function "onAddE ...

How to implement dynamic aggregate functions with parameters in Express and Mongoose

I have implemented an aggregate function in mongoose to fetch some data, with a static implementation. app.get("/male",function (req,res) { Record.aggregate([ { $match: {"gender": "male"} }, { $group:{ _i ...

How can we maintain line breaks in Textfields when using React-Admin and Material UI?

Currently, I am working with React-Admin and encountered an issue where my database field contains line breaks (\n). However, when I try to display it on a page using the following code: <TextField source="extra_details" /> The line breaks are ...

What could be the reason for Ajax not functioning on my webpage?

Seeking assistance as Ajax functionality is not working. Following a tutorial from this source, Ajax box PHP, the code functions properly. However, when implemented on a different page, it fails to work. Below are the provided codes: <!DOCTYPE html&g ...

Unable to modify the value of data using the data() method

Just a basic HTML code snippet <div class="this" data-info="false"></div> $('.this').data('info'); This will correctly output: false $('.this').data('info', 'true'); data-info remains u ...

A step-by-step guide on integrating vuetify-component into codeceptjs

When attempting to write tests using codecept.js, I am facing difficulties accessing the vuetify components. <v-layout> <v-flex xs7> <v-text-field ref="video1min" v-model="video1min" :rules=" ...

What is the best way to navigate to a new page following an ajax request in AngularJS

I have implemented angularjs and nodejs in my project to handle authentication. After a successful background authentication, I need to know how to redirect the user to the dashboard. Below is the login section of my code: <div ng-controller="loginCt ...

Communicating between iframes and parent elements via events

I'm trying to trigger an event in my iframe using the following code: $('body').trigger('my_event'); However, I want to bind this event on my main page that contains the iframe like this: $('iframe').find('body&ap ...

When the onClick method is triggered, it retrieves a single object from json_encode

Currently, I am using the json_encode method on data extracted from a table. After applying a var_dump to this variable, it reveals three objects: {"id": "5"} {"id": "6"} {"id": "7"} Here's my process: I have an image with an onclick function: < ...

"Clicking on the hamburger menu causes the webpage to reset its scroll

I recently integrated a mobile hamburger menu into my website, which is primarily built around a single page. However, I noticed that whenever I open the menu, it automatically scrolls to the top of the page regardless of where you were previously scrollin ...

Tips for effectively crafting a component capable of managing both a value and an observable for that specific value

I'm actually curious about two things. When is it appropriate to pass an observable of an object into a component versus resolving it with the | async method? If I want to create a versatile reusable component that can handle both scenarios - accept ...

Error: SvelteKit server-side rendering encountered a TypeError when trying to fetch data. Unfortunately, Express is not providing a clear TypeScript stack trace

I've been monitoring the logs of the SvelteKit SSR server using adapter-node. After customizing the server.js to utilize Express instead of Polka, I noticed some errors occurring, particularly when the fetch() function attempts to retrieve data from ...

The solution for fixing contenteditable is as follows:

I am currently working on a script to clean up pasted text within a contenteditable div. While the script is functioning well for most part, I have noticed that in Firefox, line breaks get removed when the text is copied within or between the divs. Does ...

Tips on displaying the appropriate object value in a text field based on the selection from a dropdown menu

In my Ruby on Rails form, I have a dropdown menu with various category names: <td> <div class="div1"> <%= f.collection_select(:category_id, Category.all, :name, id: 'category_select', :include_blank => & ...

An issue in Node.js NPM PDFkit arises when generating PDF tables with Voilab pdf table, leading to paragraph errors in the resulting

Greetings everyone, I appreciate you taking the time to visit. I am currently facing some challenges with Voilab PDF Kit, a library for PDFkit that is designed to assist in organizing tables for NPM Pdfkit. After successfully generating a table, I attemp ...

"An issue with PHP not receiving any data from AJAX POST request

I've been working on creating a login using AJAX. The issue I'm facing is that when the AJAX function posts data to the PHP file, the data is empty when trying to retrieve it in PHP. Here is my AJAX posting code: function validateUser() { var ...

Triggering transitionend event once with an added if condition

Currently, I have an application of an if statement that examines whether an element contains a style attribute. In the event that the style attribute is absent, it appends inline styling. Conversely, if the style attribute exists, it is removed. Furthermo ...

difficulty in making an https request

My application was developed using OFFICEjs and was functioning properly on LOCALHOST. However, last week it suddenly started throwing an error message - "XHR Error." This issue arose out of nowhere, as I hadn't made any changes to the code over the w ...