dou31797719 2014-04-30 10:10
浏览 139

jQuery文件下载+接收csv

I'm trying to create an excel file with the jquery library jquery file download. This is what I have now:

var data = {{ tableresults|json_encode|raw }};

$('#exporttocsv').click(function(){
    $.fileDownload('dashboard/exporttocsv/' + data, {
        successCallback: function (url) {

            alert('You just got a file download dialog or ribbon for this URL :' + url);
        },
        failCallback: function (html, url) {

            alert('Your file download just failed for this URL:' + url + '
' +
                    'Here was the resulting error HTML: 
' + html
            );
        }
    });
});

In my function I have this:

public function exporttocsvAction(Application $app, Request $request)
{
    $data = $request->request->get('data');

    header("Content-Type: text/csv");
    header("Content-Disposition: attachment; filename=test.csv");
    header("Pragma: no-cache");
    header("Expires: 0");

    $output = fopen("php://output", "w");

    foreach ($data as $row)
    {
        fputcsv($output, $row, ',');
    }

    fclose($output);
    exit();
}

But when I dump my $data variable in my function I just get a string like this:

string(271) "[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"

How can I make sure that I get an array in my php function? I've also tried {{ tableresults }} without json_encode and raw but that gave a syntax error:

var data = <br />

UPDATE:

this a dump of the array I send to my view: http://pastebin.com/Y58aLqBX

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入