I don't know where I'm going wrong.
Client side, I send the "user" information.
$.ajax({
type: "POST",
url: "/user",
data: JSON.stringify({ "user": "John"}),
contentType : 'application/json',
dataType: "json"
})
.done(function() {
alert( "done");
})
.fail(function() {
alert( "fail");
})
On the server side,
app.use(bodyParser.json());
app.post('/user', function (req, res) {
console.log(req.body.user);
res.end();
});
This results in the console.log correctly recording "John", but on the client side I still get a "fail" as an alert. Can't figure out why.
I'm using latest versions of node, express and jquery.
Thanks.
This was missing:
res.contentType('json');
res.send({ some: JSON.stringify({response:'json'}) });