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>
</aside>
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": "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.
Jason Knight
The less code you use, the less there is to break
The querystring module: nodejs.org/api/querystring.html
Will parse your post data into a structure FOR YOU. From there just write it to your file using "File System" with fs.writeStream.
nodejs.org/api/fs.html
Assuming you have a server-side .js for node.js that your form is submitting to... you do have that, right?
All you've shown us is client side code, and client side code cannot write to the local filesystem. (well, there is localStorage, but that's different). You want to write to a file, you generally need server-side code... aka what you should have node.js installed for.