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

Is Q.js capable of functioning independently from node.js and require()?

Currently experimenting with the latest version of q.js to integrate promises into my ajax calls without utilizing node.js at all. I retrieved the most recent version from https://github.com/kriskowal/q and only included q.js in my project. While testing, ...

Conceal the div element if the screen size drops below a certain threshold

Is it possible to hide a div element when the browser width is less than or equal to 1026px using CSS, like this: @media only screen and (min-width: 1140px) {}? If not, what are some alternative solutions? Additional information: When hiding the div eleme ...

The excessive use of Selenium Webdriver for loops results in multiple browser windows being opened simultaneously, without allowing sufficient time for the

Is there a way to modify this code so that it doesn't open 150 browsers to google.com simultaneously? How can I make the loop wait until one browser finishes before opening another instance of google? const { Builder, By, Key, until } = require(& ...

Convert the jade file to an HTML file while keeping the original file name

I'm currently attempting to configure Jade in a way that allows me to save my Jade files as HTML files while retaining the same file name. For example, I would like the file views/index.jade to be saved as dist/index.html This should apply to all ad ...

What is the best way to output partial Haml in a Padrino controller?

Currently, I am working on an Ajax request where the backend may render a partial Haml and send it back. Unfortunately, I encountered the following error: Padrino::Rendering::TemplateNotFound at /feedhtml Below is the snippet of the backend code being ...

Utilizing asynchronous operations in MongoDB with the help of Express

Creating a mobile application utilizing MongoDB and express.js with the Node.js MongoDB driver (opting for this driver over Mongoose for enhanced performance). I am aiming to incorporate asynchronous functions as a more sophisticated solution for handling ...

In order to add value, it is necessary to insert it into the text box in HTML without using the "on

example <input type="text" id="txt1" onChange="calculateTotal();" /> <input type="text" id="txt2" onChange="calculateTotal();" /> <input type="text" id="txt3" onChange="updateValue();" readonly/> <input type="text" id="txt4" onChange= ...

"Optimizing navigation with dynamic link routing in AngularJS

I am working on a list of apartments displayed using ng-repeat. I need each apartment to be a clickable link that directs the user to view more details about that specific apartment. However, I am facing an issue where the links are not being repeated dyna ...

Is there a minimum height restriction for v-select in Vuetify.js?

Looking at the code snippet provided below, I am facing an issue while trying to decrease the height of a v-select element. It seems like there is a minimum limit set for the height, as reducing it beyond height = 40 doesn't have any effect. Is there ...

The render props on the child component are not appearing on the screen as expected

Recently diving into React Native, I created a stateless component designed to iterate through props that contain objects with arrays of tags. The goal was to extract and display a single tag from each array item. (Refer to the console log in the screensh ...

Using Rails and AJAX to submit a form and dynamically update the page

When designing an index page, I included a form to create a new object. However, upon submitting the form, the page fails to update with the new object without undergoing a full refresh. The form is successfully submitted and the object is created, but the ...

Slick.js integrated with 3D flip is automatically flipping after the initial rotation

I'm encountering an issue with my CSS3 carousel and 3D flipping. Whenever I navigate through the carousel and flip to the next slide, the first slide seems to automatically flip/flop after completing the rotation. You can see a visual demonstration o ...

When working with the Google Sheets API, an error occurred: "this.http.put(...).map is not a valid

Having difficulty with a straightforward request to the Google Sheets API using the PUT method. I followed the syntax for http.put, but an error keeps popping up: this.http.put(...).map is not a function. Here's my code snippet: return this.http ...

What is the best method for extracting data from a node?

Issue: Upon sending a get request to node using the fetch API, an error is encountered. Refer to comment in code for details server.js const express = require('express'); const app = express(); const bodyParser = require('body-parser&apo ...

Redis VS RabbitMQ: A Comparison of Publish/Subscribe Reliable Messaging

Context I am working on a publish/subscribe application where messages are sent from a publisher to a consumer. The publisher and consumer are located on separate machines, and there may be occasional breaks in the connection between them. Goal The obj ...

Save information to the database automatically without the need to click on 'Submit' or 'Next' each time

I am a student about to conduct an online experiment. For this experiment, participants will visit a website similar to this one: . The website tracks a) the buttons they click and b) how long each button is pressed. This tracking is done to determine how ...

Issue: Upon attempting to connect to a vsftpd server deployed on AWS using the npm module ssh2-sftp-client, all designated authentication methods have failed

Code snippet for connecting to the vsftpd server sftp.connect({ host: "3.6.75.65" port: "22" username: "ashish-ftp" password: "*******" }) .then(() => { console.log("result") }) .catch((err)=>{ ...

The dropdown menu in AngularJS is unable to retrieve the selected index

Presently, I have a dropdown menu: <select class="form-control" name="timeSlot" ng-model="user.dateTimeSlot" ng-change="dateTimeChanged(user.dateTimeSlot)" ng-blur="blur29=true" required style="float: none; margin: 0 auto;"> ...

PHP: A guide on validating textboxes with jQuery AJAX

How can I use jQuery AJAX to validate a textbox on focusout? The validation process includes: Sending the value to a PHP page for server-side validation Displaying an alert message based on the validation result I have only impl ...

"Unexpected issue with jQuery AJAX Post functionality on a shared server causing data not to

I'm currently facing an issue with my code that allows comments to be added to a php page without needing to refresh the page. While everything is functioning properly on localhost, I encountered a problem when testing it on my justhost account. The ...