I wanna do this: Grab some data from my dom with javascript, save them to a variable and then send that to node js, grab that with express and finally save that into database. client side javaScript:
var tags = ["apple","orange","green"];
$.ajax({
type: "POST",
url: '/posts',
data: { tags : tags },
success: function(data)
{
alert("success!");
}
});
now I am trying to grab that data with express like this:
My server code:
/***** CREATE A POST *****/
app.post('/posts', function (req, res) {
//code
var tags = req.body.tags;
// create that post
});
But that doesn't work correct. what is the problem?
/postsPOST call, and try doing console.log(req.body.tags), and see if you are successfully receiving the data