仅使用javascript在服务器上读取/写入txt文件,而不涉及任何服务器端语言 [英] Read / Write txt file on server using only javascript without involving any server side language

查看:43
本文介绍了仅使用javascript在服务器上读取/写入txt文件,而不涉及任何服务器端语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个简单的HTML/Javascript应用程序.此应用程序在文本区域中向用户显示随机文本消息.我有15到20个此类短信,最多不超过500个字符.我不想将这些消息保存在数据库中.我有两种情况-

I'm working on a simple HTML/Javascript application. This application shows a random text message to the user in a text area. I have 15-20 such text messages of at most 500 characters. I don't want to save these messages in database. I have two scenarios -

  1. 我为每个邮件有多个.txt文件,然后通过使用仅用于读取随机txt文件并显示文件内容的j​​avascript在textarea中.
  2. 用户在单独的文本区域中输入一条消息,然后通过按保存按钮,该邮件的新txt文件应为已创建.

我一直在搜索如何在javascript中读取/写入文件,我发现了这两篇文章-是否可以仅使用JavaScript?如何读取和写入文件使用JavaScript .
但是这些文章是关于在客户端读取文件或从文件输入类型读取文件.

I've been searching how to read / write files in javascript, I found these two posts - Is it possible to write data to file using only JavaScript? and How to read and write into file using JavaScript.
But these posts are about reading file on client side or reading file from file input type.

https://stackoverflow.com/a/21012689/1930283

此建议是关于使用某些服务器端语言的.
是否有任何方法可以仅使用Javascript读写txt文件.

This suggestion is about using some server side language.
Is there any way to read and write txt files using Javascript only.

推荐答案

仅当JavaScript是您的服务器端语言(例如,使用Node.JS)时.

Only if JavaScript is your server side language (e.g. with Node.JS).

默认情况下,服务器不允许您向其中写入文件.那将是一个可怕的安全问题.

Servers don't let you write files to them by default. That would be a horrible security problem.

这篇关于仅使用javascript在服务器上读取/写入txt文件,而不涉及任何服务器端语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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