How to organize save the file to the user?

On the database there is a table on which you want to export in csv format.

On the website there is the button to which was attached this js function:
function export_csv() {
$.ajax({
 url: '/prepare_csv',
 method: 'post',
 dataType: 'html',
 success: function() {
 window.open('static/temp/out.csv', '_blank');
}
});
 }

Literally, the server is queried, the function of preparing . csv file and puts it in the folder /static/temp when the query to the server is successful, a pop-up window opens and downloads the file. But the problem is that browsers save the file in the cache, and subsequently if there are changes in the database and in the file that are exported continues to be downloaded the old version of the file. New starts only be downloaded if you manually clean your browser cache. Besides, IE automatically blocks pop-UPS.
April 4th 20 at 12:56
3 answers
April 4th 20 at 12:58
function export_csv() {
$.ajax({
 url: '/prepare_csv',
 method: 'post',
 dataType: 'html',
 success: function() {
 window.open('static/temp/out.csv?_='+(new Date()).ValueOf(), '_blank');
}
});
 }
April 4th 20 at 13:00
generate a unique file and give the address on it at which and go.
April 4th 20 at 13:02
Either the file record to the name of the random value, or issue it with the header so that the browser perenakachivat always prevent caching, etc.

Find more questions by tags JavaScriptWeb Development