I have an html form that has several fields which I package in a JSON, and I need to send this to a server. I have the following code on the front end:
var data = {
//data here
};
var xhr = new XMLHttpRequest();
xhr.open("POST","localhost:8000/add",true);
xhr.setRequestHeader("Content-Type","application/json");
xhr.send(data);
And then on the server, I have this code to receive it:
app.post('/add', function(req,res) {
console.log(req.body.name);
res.json(req.body.name);
});
It sends nothing; what do I need to do to get it to send the JSON?