-2

I'm new to Node.js, and, i would like to know how to make data "transite" between html files for exemple :

I get submit.html with 2 text inputs (name and age) and a submit button, with target sub.html,

Let's say that an user submit name=Alex, age=20, How to get this data in my sub.html script(sub.js) to render these data in HTML tag ? Does i need to use socket.io or Ajax maybe ? there isn't some methods in node.js ?

Thanks for answering to these noob questions ^^

[EDIT] I've forget to say that i want a non freamwork solution (i haven't find answer on google) but it seem imposible so well.. i will use node :)

Alexandre Daubricourt
  • 3,323
  • 1
  • 34
  • 33

1 Answers1

0

You need to use a web application framework like express, koa to handle requests.

Here is one approach to above question using express as web framework:

app.get('/', function(req, res) {
  // code to render submit.html
});

app.post('/', function(req, res) {
  // gets value of the submit.html through a ajax request
  // save it in database( such as sqlite, mysql)
});

app.get('/welcome', function(req, res) {
  // retrieve stored data from database
  // render 2nd html (which displays name and age) using a templating enigne like pug (previously called jade)
});
Himani Agrawal
  • 1,242
  • 12
  • 14
  • Thanks.. Well it's sad that i need to use some freamworks but it's still great! I just have another question : Why poeples dislikes my question ? – Alexandre Daubricourt Sep 22 '16 at 19:19
  • Maybe because its a general question and not specific to node.js. Also, maybe because you can find blogs on google about this easily. – Himani Agrawal Sep 22 '16 at 19:24