如何使用Jquery创建.txt文件? [英] How can I create a .txt file using Jquery?

查看:110
本文介绍了如何使用Jquery创建.txt文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,这是我的域:example.com/index.html,我想在该域中创建一个.txt文件.结果:example.com/file.txt并显示以下信息:

Ok, this is my domain: example.com/index.html and I want to create a .txt file into the domain. result: example.com/file.txt with this info:

.js:

$('.saveButton').on('click', function (e) {
    e.preventDefault();
    $('.HTMLcontentTosave').html(); //save this html content into a file.txt
});

$.ajax可能是

非常感谢!

推荐答案

仅在浏览器中使用jQuery/javascript和通常配置的Web服务器,这是不可能的.服务器的文件系统不会以可直接从客户端写入的方式公开,这将带来很大的安全风险.

Using only jQuery/javascript in the browser, and a typically configured web server, this isn't possible. The filesystem of the server is not exposed in such a way that it is directly writeable from a client, that would be a rather large security risk.

要使其成为可能,您将需要使用一些服务器端代码,例如PHP,以帮助在服务器上写入文件.此时,您可以将所需的内容和文件名作为请求发送给服务器端代码,然后该代码可以将其写入服务器文件系统上所需的位置.

To make it possible, you will need to employ some server side code, such as PHP to assist in writing the file on the server. At that point you can send the desired content, and name of the file as a request to the server side code and that code can then write it to your desired location on the server's file system.

请确保采取足够的保护措施,以便您指定的某些用户只能写入某些(安全)文件,否则您可以打开前面提到的安全漏洞.

Make sure to employ adequate protections so only certain (safe) files can be written to, by the certain users you specify, otherwise you could open the previously mentioned security hole.

这篇关于如何使用Jquery创建.txt文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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