doufeixi6014 2015-10-03 15:35
浏览 127
已采纳

在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 :)

  • 写回答

1条回答 默认 最新

  • duankan8739 2015-10-03 16:10
    关注

    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);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)