通过jquery / javascript下载php genereted csv文件 [英] Download php genereted csv file though jquery/javascript

查看:157
本文介绍了通过jquery / javascript下载php genereted csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从php下载一个csv文件,但是我需要通过jquery / javascript来执行。

I can download a csv file from php, but I need to do it via jquery/javascript.

那是什么最好的解决方案?如何做?

what would be the best solution for that? how to do it?


  • 将php生成的csv文件保存在tmp目录中,并通过jquery / JS下载,但是如何(应用程序在内部使用) / li>
  • 将数据数据发回到前端,全部在jquery / JS中。

其实我想更新页面上的数据同时下载更改的行!
我不能使用任何插件。

Actually I want to update data on page and same time download changed rows! I can not use any plug-in of any kind.

编辑:
好​​的!这里是完整的问题,我忘了提到。

Ok! HERE is the full problem, i forget to mention.

我有一个页面,从DB的一些行,

I have a page with some rows from DB,


  • 我想更新DB中的所选行

  • 同时获取更改值并更新页面

  • 下载更改csv中的行

在一个按钮中,单击

我不能使用不同的按钮保存数据和下载文件,因为在db中更新行后,我将如何获取最后更新的行?
我有限的知识,我可以得到json响应和更新页面或下载文件不是两个!

I cant use different buttons to save data and download file because after updating rows in db how would I get last updated rows? With my limited knowledge, I can just get json response and update page Or download file not both!

推荐答案

这是我如何解决它:)

我在JS中从json返回的数据中创建了csv字符串。
和使用的数据URI方案如下:
我做了一个链接,并下载了.csv文件。

I made csv string out of json returned data in JS. and used data URI scheme like here: I made a link and that downloads .csv file.

var uri = 'data:application/csv;charset=UTF-8,' + encodeURIComponent(csv_ouput);
$('#csv-btn-div').append('<a href="' + uri + '"download="csv-export.csv">Download CSV</a>');

还有另一个解决方案,如果你想要文件保存对话框出现!

There is another solution, if you want file save dialog to appear!

感谢所有!

这篇关于通过jquery / javascript下载php genereted csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆