Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
Send the form to the server and receiving data back? - Q&A

Send the form to the server and receiving data back?

0 like 0 dislike
Submit the form to the server:

Get it on the server:'/add',urlencodedParser,function (req,res) { console.log(req.body); });

How to make sending Ajax'? What could I send from the server the form data back and display them.
asked by | 12 views

2 Answers

0 like 0 dislike
The answer is easily searched by the search engine.
var data = $('#myform').serialize(); $.ajax({ type: "POST", url: "http://localhost:3000/add?", data: data, success: function(msg) { alert(msg); } });

And don't forget to add the server to function.
answered by
0 like 0 dislike
Turned out to make so:
\r\r\r\r\r\r\r\rlet myButton = document.getElementById('formsub');\rmyButton.addEventListener('click',function (ev) {\rlet name = document.forms['myform'].elements['login-name'].value;\rlet pass = document.forms['myform'].elements['login-name'].value;\r\rlet obj = {\rname:name,\rpass:pass\r};\rfetch('/add', {method: 'POST',body:JSON.stringify(obj),headers:{'content-type': 'application/json'}})\r.then(function (response) {\rreturn response.json();\r})\r.then(function (data) {\rlet us = document.createElement('h2');\rus.innerHTML =;\rlet mydiv = document.getElementById('tester');\rmydiv.appendChild(us);\r})\r.catch(alert);\r})\r
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers


13.3k users

24,788 questions
46,220 answers
13,322 users