Saturday 1 April 2017

Sending and proceeding POST request

I have very simple node.js server which has

var express = require('express');
var app = express();

app.post('/savearticles', function (req, res) {
    res.send(req.body);
});

and not much more difficult javascript code

    var xmlHTTP = new XMLHttpRequest();
    xmlHTTP.onreadystatechange = function () {
        if (this.readyState === 4 && this.status === 200) {
            alert(xmlHTTP.responseText);
        }
    }
    xmlHTTP.open('POST', '/savearticles', true);
    xmlHTTP.setRequestHeader('Content-Type', 'application/json');
    xmlHTTP.send('postparameter');

It returns undefined (checked by returning (typeof res.body)). What Am I doing wrong?



via R. Korol

No comments:

Post a Comment