weixin_33674976 2016-05-02 23:44 采纳率: 0%
浏览 91

在NodeJS中获取发布数据

I believe the answer to this question is out of date because of this answer.

I've read solutions about a npm packaged called body-parser, but I don't want to use it if I can find another way. I just simply want to parse POST data in node.

I have an ajax function like this:

$.ajax {
    url: '/foo',
    method: 'POST',
    data: {foo: "foo", bar: "bar"}
}

something like:

app.post('/foo', function(req, res) {
    var postFoo = req.foo; // How do I do this? 
});
  • 写回答

2条回答 默认 最新

  • weixin_33694172 2016-05-02 23:52
    关注

    Try

    req.body.foo
    

    like this:

    app.post('/foo', function(req, res) {
        var postFoo = req.body.foo;
    });
    

    The request can hold a lot of information such as the requesting user, headers, and the body of the request. The body holds the actual data that was passed along by the ajax-request.

    评论

报告相同问题?