How to pass AJAX output to file upload in Javascript?

We have a REST API that emits JSON, from where we can use the source data (using AJAX). We want to make AJAX calls when each call retrieves a small piece of data (say 5000 lines or so), and then it is written to the CSV file in the browser as a download.

It seems that if we have all the data in the JS memory, then writing it to a CSV file is not difficult, but if we want to write 100K records, then we are forced to take all 100K in one shot, and then create the file in one go.

Instead, we feel that it will be much softer on the server and client to load small chunks and transfer them to a file. Is there any way to do this?

(We are currently using jQuery 2.0.0, but do not mind using another library to do this)

+6
source share
1 answer

Basically you are looking for paging records ... for this you can do

  • Find the total number of records in the database
  • How to share your notes / no calls
  • Merge all data coming from different calls

to make a multiple call using jquery you can do it 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!" ); } }); 

there are several ajax calls in the code and finally data merging ... the same thing on the server side what you need to do if you use C # than TPL (Task parellel library) is a good option ... for each call you need to call with page number

+1
source

Source: https://habr.com/ru/post/989918/


All Articles