Reputation: 3307
We have an REST API emitting JSON from where we can source data (using AJAX). What we want to do is to be able to do AJAX calls where each call fetches a small chunk of data (say 5000 rows or so), and then have it written out to a CSV file on the browser as a download.
It seems that if we have all the data in JS memory, then writing it out to CSV file is not hard, but if we want to write out 100K records, then we are forced to fetch all 100K in one shot and then produce the file in one go.
Instead, we feel it would be much gentler on both server and client to download small chunks and stream it out to the file download. Is there a way to do it?
(We are presently using jQuery 2.0.0, but don't mind using a different library to get this done)
Upvotes: 7
Views: 1560
Reputation: 176896
Basically you are looking for paging of record...for this you can do
for making multiple call using jquery you can do like this
$.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ) ).done(function( a1, a2 ) {
// a1 and a2 are arguments resolved for the page1 and page2 ajax requests, respectively.
// Each argument is an array with the following structure: [ data, statusText, jqXHR ]
var data = a1[ 0 ] + a2[ 0 ]; // a1[ 0 ] = "Whip", a2[ 0 ] = " It"
if ( /Whip It/.test( data ) ) {
alert( "We got what we came for!" );
}
});
in code there are multiple ajax call and at last it merging data ...that same thing on server side you have to do if you are using C# than TPL (Task parellel library) is good option...for each call you need to call with the page number
Upvotes: 1