Wednesday, 12 April 2017

How can I receive the post data from jquery in NodeJS

This is my jQuery code:

$.ajax({
            url: 'http://localhost:3000/generatePDF',
            data: '{"data": "TEST"}', /* It is about the content "TEST" that I would like to receive/get */
            type: 'POST',
            success: function (data) {
                console.log('Success: ');
            },
            error: function (xhr, status, error) {
                console.log('Error: ' + error.message);
            }
        });

This is my code in my NodeJS server:

app.post("/generatePDF", function (req, res) {
    console.log(req);
    res.sendStatus(200);
    return;
});

I would like to receive my POST data that i send with the jQuery code. How can I do this? Or can I do it in plain Javascript?



via Johnnybossboy

No comments:

Post a Comment