Wednesday, 15 March 2017

Nodejs - req.body.name undefined in GET with express [duplicate]

This question already has an answer here:

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