0

In a Node.js app running Express, I have a route setup to take POST requests and create database objects.

app.post('/', function(req, res) {
    // create object in DB
    res.send('');
    res.status(201).end();
});

I understand a 201 status code indicates successful creation of the object. I wish to receive a 201 status in my jQuery POST on the client side:

$.post('/', sendData).done(function(receiveData, status, xhr) {
    alert(xhr.status); // returns 200 status
});

However, I am receiving a 200 status, not the 201 I am trying to send.

What can I change to receive at the client the 201 status code I am trying to send from the server?

4

1 回答 1

2

文档

发送前尝试设置状态:

app.post('/', function(req, res) {
    // create object in DB
    res.status(201).send('');
});
于 2016-05-13T17:46:43.830 回答