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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退