0

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>

I am running whole folder on 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 whenever 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",
  },

  { "person": "efg",`enter code here`
     "email": "456@mail.com",
     "message": "bcdefg",
  },

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 database. No, it is not an assignment given by the teacher, I am a solo learner, and I cannot able to solve. I came across many other forums but I am confused. If there are any complex commands in your code, It would be good if u explain me the code. (Explaining in terms of 5yr old kid).

Faraz
  • 1
  • 1
  • Read [this](https://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax) SO post for a starter. Although this is not an assignment this site is not set up to write code for you. – Jeroen Heier Jul 08 '18 at 06:50

1 Answers1

0

Assuming you have written the code for saving/retrieving the JSON and that you are appending the input values to the JSON file: reverse the Array server side (whilst fetching) and send it to the client. The first element @ client will be the last from the server file.

If you didn't write any code: check this page. For reading/writing files using nodejs, the internet is packed with examples for that. It's like Jeroen Heier said: this site is not set up to write code for you.

console.log([
  { "person": "abc",
     "email": "123@mail.com",
     "message": "abcdefg",
  },
 { "person": "efg",
     "email": "456@mail.com",
     "message": "bcdefg",
  },
].reverse()[0]);
KooiInc
  • 119,216
  • 31
  • 141
  • 177