简体   繁体   English

jQuery XML导出或简单JavaScript文件下载

[英]jQuery XML export or Simple JavaScript file download

I have dynamically created a xml string form a JSON object returned from server. 我已经从服务器返回的JSON对象中动态创建了xml字符串。 I need to give the user to download this as a file so that when the user click the button named export he/she receives a downloadable.xml file and can be save d on local machine. 我需要让用户将该文件下载为文件,以便当用户单击名为export的按钮时,他/她收到一个downloadable.xml文件,并且可以将其保存在本地计算机上。

Is this possible? 这可能吗?

I was recently looking for something similar, and came across Downloadify . 我最近在寻找类似的东西,并遇到Downloadify It appears to use a feature of Flash 10 to work around the filesystem limitation of JavaScript. 它似乎使用Flash 10的功能来解决JavaScript的文件系统限制。

Have you generated the file on the server or on the client? 您是否在服务器或客户端上生成了文件?

If you have generated the file at the server you can use the content-disposition header. 如果您在服务器上生成了文件,则可以使用content-disposition标头。 You also need to set the content type to application/xml or text/xml. 您还需要将内容类型设置为application / xml或text / xml。

If you have generated the file using jQuery, then it isn't possible for the user to save it locally. 如果您是使用jQuery生成的文件,则用户无法将其保存在本地。 Javascript isn't allowed access to the file system. 不允许Javascript访问文件系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM