我有像下面这样的KOA:
var koa = require('koa'),
bodyParser = require('koa-body-parser'),
router = require('koa-router'),
app = koa();
app.use(router(app));
app.use(bodyParser());
app.post('http://localhost/get',getit);
function *getit(){
 console.log(this.req.body); //undefined
}
然后通过jquery ajax发送一个帖子要求:
 var xhr = $.ajax({
            type: 'POST',
            dataType: 'json',
            contentType: 'application/json',
            url: 'http://localhost/getit',
            data: {"name":"me"},
            success: function(response) {
            }
        });
但是在koa和this.req我找不到我的数据。在谷歌浏览器开发人员工具中,我可以看到标题,并且一切正常,但是我在koa中看不到它。
更新资料
正确的是:
   function *getit(){
 console.log(this.request.body); //undefined
}
解
根据评论,对我来说正确的是
this.request.body,this.req.body也不正确的。