I have a rails application where I'm displaying charts using the gridList library. The chart data is fetched from a controller method (in JSON format) asynchronously using AJAX. When the page is loaded initially, each gridlist item shows loading icon and at the same time ajax call is made to the server to fetch the data. Each individual grid item makes a seperate ajax call. The charts are being rendered properly but the issue is that while the AJAX calls are ongoing, the server does not respond to any other requests like refreshing the page or changes in routes. It get blocked until all the charts are loaded, after which the previously called action occurs.
It is a server side issue as the javascript code on front-end works fine while the AJAX call is ongoing.
The grid items are rendered using the partial shown below
%li.grid_item{ data: { id: chart.id } }
.chart-loading
// loading icon
.chart-content.hide
// chart-content currently hidden.
:javascript
var chart_id = "#{chart.id}"
$.ajax({
url: "#{get_data_charts_path(chart.id)}",
success: function (res) {
var data = JSON.parse(res)
hideLoadingChart(chart_id) // hides loading and shows chart-content
renderChart(data) // plots chart for the data
}
})
And the partial is called using the following command -
.grid-container
%ul#grid.grid
= render partial: 'chart', collection: @current_user.get_charts
What could be the problem. Is there a way to cancel all the current AJAX calls when a new request is made to the server.
Is this design where I'm making multiple AJAX calls for each chart correct. I want the charts to load as and when the data is available and not all at once in the end.