在Jquery中获取PHP输出

i know PHP is a server side script and js is a client side but i have an issue..

I needed to bypass the browser security when doing an ajax request to another domain and it was difficult for me to be honest i had no idea what i was doing so i turned to php.. wooohooo....

The issue is i can only use JS and CSS to run arbitrarily ontop of my tracking system!

I wanted to add a newsfeed.csv so i made this php code to get the csv and convert it and store it into the variable $json.

    <?php
$file="http://www.jonar.com/portal/partner/js/newsroomcustomer.csv";
$csv= file_get_contents($file);
$checkit = utf8_encode($csv);
$array = array_map("str_getcsv", explode("
", $checkit));
$json = json_encode($array);
?>

Is there a way to do an ajax get to get the variables output? meaning the json format of my csv..

This way i can have my PHP script on my webserver and it will be able to grab any link on any domain..

Thanks guys :)

Like the comment of Julio said:

Use echo to print the contents of the generated JSON string. It's as easy as echo $json.


Once your PHP script outputs the correct JSON string, you can send an AJAX request to your script with the following code (assuming you're using jQuery, which will make your life easier):

$.get('script.php', function (data) {
   console.log('Data received: ', data);
});