This question already has an answer here:
- Express.js req.body undefined 13 answers
With POST everything works well
But with the method GET req.body.name response undefined Tell me, what's my mistake?
app.get('/data', function(req, res) {
var product = {
id: products.length + 1,
name: req.body.name
};
products.push(product);
var i = products.length - 1;
res.send("<h2" + products[i].id + "</h2>" + "<p>" + products[i].name + "<p>");
})
$('button').click(function() {
$.ajax({
type: "GET",
url: "/data",
data: {"name": "123321"},
success: function(data) {
$('.products table').append(data);
}
});
return false;
});
via Danil NKTEL
No comments:
Post a Comment