I have a PHP file dataAPI.php
which returns an array of data that is either serialized as JSON or (as I'm trying to implement) CSV. dataAPI.php
is accessed exclusively through AJAX calls, which has worked fine so far with JSON data.
The problem is, I want to also have an export button on the client-side, which when clicked, would send another AJAX call to return the same data serialized in the CSV format. I know I can't send files over AJAX, so how would I go about doing this?
I've thought of creating CSV files on the server side, and then sending a redirect-url as the response to my AJAX request. If I did this though, how could I prevent two requests overwriting each others files and remove already accessed/old csv files? Is there a better way? Any help is appreciated.