NodeJS For Beginners: Working with JSON Data with Express and the Body Parser Module

preview_player
Показать описание
Learn how to accept JSON data with express and the body parser module. JSON is language independent and allows applications that may be written in different programming languages to communicate with each other. In this example we use ajax to post data from a form to our server.
Рекомендации по теме
Комментарии
Автор

that was epic bro your teaching style is very very good

prathamesh
Автор

I don't really know jquery so I converted it to vanilla JS:

const form =
form.addEventListener("submit", (e) => {
e.preventDefault();

fetch("/post", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify([
form.children[1].value,
form.children[3].value,
]),
})
.then((response) => {
if (response.ok) return response.json();
throw new Error("Something went wrong");
})
.then((response) => {
console.log("sucess");
console.log(response);
});
});

ShrubScotland