如何将表单保存到pc中 [英] How to save form to file in pc

查看:110
本文介绍了如何将表单保存到pc中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我想将我的HTML表单保存到计算机中的某个文件中。每当我点击提交时,我希望文件得到更新。后来我想明智地获取文件数据组。这可能只使用JS,AJAX,JSON吗?



这是我当地的html文件。



Hi! I want to save my HTML form to a certain file in my computer. and whenever I click on submit, I want the file to get updated. and later I want to fetch the file data group wise. is this possible by using JS, AJAX, JSON only?

This is my local html file .

<aside id="sidebar">
    <div class="dark">
    <h3> Get a Quote</h3>
    <form class="quote" id="contactForm" method="POST" action="/contact">
    <div>
    <label>Name</label><br>
    <input type="text" name="Name" id="person">
    </div>
    <div>
    <label>Email</label><br>
    <input type="email" name="Email Address" id="email">
    </div>
    <div>
    <label>Message</label><br>
    <textarea placeholder="Message" name="query"></textarea>
    </div>
<input type="submit" value="Send">
</form>
</div>





Iam正在运行localhost服务器使用node.js.现在,当我点击提交时,我希望表单输入以JSON格式存储在某个文件夹[例如C:\ Users ..]中,就像数组一样。例如,文件可能看起来像



[

{person:abc,

email:123@mail.com,

留言:abcdefg,

},

{person :efg,

email:456@mail.com,

留言:bcdefg,

} ,

]

因此,当我点击提交按钮时,文件应自动更新并将下一个输入保存为数组。

第二部分是,点击按钮时,从最近到旧获取商店输入值。所以基本上第二部分将包含一个带按钮的基本HTML页面。当我点击按钮时,它应该显示最近存储的数组,对于我们从上面的例子中第一次点击应该显示



{ person:efg,email:456@mail.com,message:bcdefg,},



和下一次点击应该显示



{person:efg,email:456@mail.com,message:bcdefg,},

{person:abc,email:123@mail.com,message:abcdefg,},



所以基本上是递减的顺序。并希望使用AJAX解决。第一部分是使用JS,DOM,JSON保存文件输入。第二部分是获取文件数据AJAX。目前我不想使用PHP,ASP或任何本地浏览器存储,或在线数据库。



我尝试过:



我遇到过很多论坛,我感到困惑,建议我如何解决这些问题。我知道第二部分,但我无法完成第一部分。



Iam running localhost server by using node.js. Now, when I click on submit, I want the form input to be stored in the certain folder[for example C:\Users..] in JSON format like an array. For example, the file may look like

[
{ "person": "abc",
"email": "123@mail.com",
"message": "abcdefg",
},
{ "person": "efg",
"email": "456@mail.com",
"message": "bcdefg",
},
]
So when ever i am clicking on submit button the file should automatically get updated and save the next input as an array.
The second part is, fetching the store input value from recent to old when clicking on the button. so basically the second part would contain a basic HTML page with a button. and when I click on the button, it should show me the recent group of an array which is stored, for us from the above example the first click should show

{ "person": "efg", "email": "456@mail.com", "message": "bcdefg", },

and the next click should show

{ "person": "efg", "email": "456@mail.com", "message": "bcdefg", },
{ "person": "abc", "email": "123@mail.com", "message": "abcdefg", },

so basically in a decreasing order. and want to solve using AJAX. The first part is saving file input by use of JS, DOM, JSON. The second part is fetching file data AJAX. at present I do not want to use PHP, or ASP or any local browser storage, or online data base.

What I have tried:

I came across many forums, and I am getting confused, Suggest me regarding the codes and how to solve it. i know the second part, but I cannot able to do the first part.

推荐答案

这真的不是一个好主意。

如果你意味着将文件存储在客户端上,然后你不能:出于安全原因,Javascript / HTML没有任何直接访问客户端文件系统的权限。



如果你的意思是在服务器上,那么这是一个更糟糕的想法。虽然它可能 - 甚至很简单,只需使用其中一个JSON包将其转换为JSON,然后使用文件系统IO将其写入磁盘 - 这将给您带来生产中的巨大问题。为什么?因为网站本质上是多用户的 - 如果你从多个用户那里写同一个文件,你会遇到像正在使用的文件这样的问题,更糟糕的是:写这个文件的最后一个人写的是任何人都可以阅读的唯一的dtaa,其他人的数据得到了抛出垃圾箱。



我强烈建议你考虑使用像SQL Server或MySQL这样的多用户数据库系统而不是JSON - 它们是专为JSON设计的设计用于数据传输,而不是存储。
That's really not a good idea.
If you mean to store the file on the client, then you can't: Javascript / HTML doesn't have any direct access to the client file system for security reasons.

And if you mean on the server, then that's an even worse idea. While it's possible - and even simple, just convert it to JSON using one of the JSON packages out there and then use the file system IO to write it to disk - it's going to give you huge problems in production. Why? Because websites are inherently multiuser - and if you are writing the same file from multiple users you will get problems like "file in use" and worse: the last guy to write the file writes the only dtaa that anyone can read, everybody else's data gets thrown in the bin.

I would strongly suggest that you consider using a multiuser database system like SQL Server or MySQL instead of JSON - they are designed for such things where JSON is designed for data transport, not storage.


这篇关于如何将表单保存到pc中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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