2015-10-06 233 views
0

流星1.2铁路由器流星1.2,this.request.body是空

Router.route('/upload', { 
    where: 'server', 
    action: function(){ 
    console.log(this.request.body); 
    this.response.end(JSON.stringify(this.request.body)); 
    } 
}); 

我正在使用前面提到issues线。

if (Meteor.isServer) { 
    Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({ 
     extended: false 
    })); 
} 

答案仍然是{}。这与流星1.2打破了吗?现在有什么解决方案?

回答

1

//这是我的路线

Router.map(function(){ 
    this.route('/posted',{where:'server'}) 
    .post(function(){ 
     console.log(this.request.body); 
     this.response.end('post request\n'); 
    }); 
}); 

//这是我的形式

<form method="post" action="http://localhost:3000/posted"> 
    <input name="test" value="blah"></input> 
    <input type="submit" value="Submit"></input> 
</form> 

//这是我的服务器的控制台上回复

//I20151026-12:27:21.421(-6)? { test: 'blah' } 

希望这有助于

+0

这只是为我节省了很多时间。这段代码非常重要,很有趣,很难找到。谢谢! – jremi