2015-10-06 131 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

相關問題