duanpai1033 2013-11-18 17:51
浏览 68
已采纳

在从Ajax返回的数据上使用Jquery方法,而不打印出数据

So I have a rather unique situation. I am using JQuery to gather some data based on two date ranges, what is returned as a response in the $data variable (I am using Ajax) I have set, is a html table.

Now I don't want the user to ever see this table, I want to use This jquery plugin to download the CSV file of that table. The question is, if the table sits inside of a $data and can be seen via the network tab in Chrom Dev Tools, under Response, is it possible to be manipulated with Jquery?

In our inhouse framework, we do the following to get Ajax Data:

    // The following belongs to a JS class method.
    data = {
        startDate : $('.startDate').val(),
        endDate : $('.endDate').val()
    }

    CT.postSynch('report/payRollReport/downloadPayRoleReport', {data : data}, function(data){
        console.log(data);
    });

We pass a data object to our Ajax wrapper, call a controller with an action (in this case downloadPayRoleReport translates to ajaxDownloadPayRoleReport()) which in turn returns an HTML table, which I can view via console.log(data)

I want to use the above linked plugin on data to then turn this html table into a csv and instant download.

Question is, can this be done?

  • 写回答

1条回答 默认 最新

  • duanhuanyou6478 2013-11-18 18:01
    关注

    You can create a jQuery object from the table. Then you can do anything to the jQuery object just like you could if it were actually on the DOM. You can always put the table on the DOM as well off screen, but I think any chance you have to not touch the DOM you should take it.

    var myTable = $(data);
    
    myTable.mySpecialTableMethodToExportToCSV();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线边框
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题