Automatic loading with jQuery Ajax Call return

I use the Ajax jQuery command to invoke a PHP script that generates a CSV file and returns a link to this file for the user to download.

I would like to make it more user-friendly by automatically downloading the download so that the user sees the Save or Open browser window instead of clicking the download link.

I assume I need to somehow change the headers in the Ajax success callback?

I'm not quite sure that I should point out my searches or even if possible.

Thank!

+3
source share
1 answer

( ) , ajax, :

<?php
header('Content-type: "text/csv"; charset="utf8"'); //adjust encoding if needed
header('Content-disposition: attachment; filename="fileNameHere.csv"');
//output document in response
?>

- , , , php.

+3

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


All Articles