function but() {
let a = 3;
let xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:8080/");
xhr.send(a);
document.write(res.text)
}
app.post('/', function (req, res) {
let a = req.name;
console.log(a);
});
// клиент
function but() {
var xhr = new XMLHttpRequest();
xhr.open( 'POST', '/ajax' );
xhr.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
xhr.send( 'field=value' );
}
// сервер
app.use( bodyParser.json(), bodyParser.urlencoded({ extended: true }) );
app.post( '/ajax', function (req, res) {
console.log( req.body );
});