If you want to go down the Ajax route, you should create a page (or route) that is specifically designed for getting just the CSV data and returning it as a json object. Lets's say you just need to know the id to generate the data, you could create csvdata.php that looks for $_POST['id'], gets the data for that id, and returns the json_encode(csvArray) data. You probably want to set the mime type header('Content-type: application/json'); This is no different than a script that provides files for example. All you need to know is what to request and what data to send with the request. If you need the CSV data on a page, you need to render a script that knows what data to send along with the request. Your templating engine should be able to render small dynamic scripts for you. In principle you want to generate a script like
...
<body>
...
<script type="text/javascript">
(function () {
var csvid = 1;
// Make ajax post to csvid.php with csvid as id
}());
</script>
</body>
You would generate a script like this, where the csvid value is set dynamically (using your method of choice for generating html/js). Always use POST to retrieve Ajax data, particularly if the data is sensitive and requires session authentication. GET in this case would be open to json array exploits.
Alternatively you could simply render the array inline without Ajax. So instead of creating the ajax request variables, you can just render a script with the array encoded in it.
Template:
<script type="text/javascript">
(function () {
var data = {jsondata};
someNameSpace.someProcessingFunction(data);
}());
</script>
Replaces {jsondata} with json_encode(csvarray);