Angularjs Express,主体解析器不解析表单数据+;对象(使用Angular.js$resource)
我正在学习angular.js$resource。就像文档中的例子一样,我有一个自定义方法Angularjs Express,主体解析器不解析表单数据+;对象(使用Angular.js$resource),angularjs,node.js,parsing,express,body-parser,Angularjs,Node.js,Parsing,Express,Body Parser,我正在学习angular.js$resource。就像文档中的例子一样,我有一个自定义方法 // some stuff {charge: {method:'POST', params:{charge:true}} //declaring custom method // some stuff // and then call the this method card.$charge({amount:9.99}); // It makes POST: /user/123/card/456?am
// some stuff
{charge: {method:'POST', params:{charge:true}} //declaring custom method
// some stuff
// and then call the this method
card.$charge({amount:9.99});
// It makes POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'}
问题在于我的express应用程序只解析对象,未命中amount=9.99&charge=true
。但如果我只发送amount=9.99&charge=true
wihtout对象(而不是通过angular的$resource),它的解析就可以了。如果我只发送对象,则相同。但不是两者都有。
所以我不能得到真正需要的charge=true
。我甚至可能得不到对象,但Angular的$resource在默认情况下会附加它,所以我不知道在调用自定义方法时如何防止附加对象
我正在使用:
express 4,正文分析器,带配置:
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(methodOverride());
和multer
所以,亲爱的社区,请帮助。我要休息两个小时。根据你的$resource声明
card.$charge({amount:9.99});
这将发送一个带有查询的POST请求:amount=9.99&charge=true
,以访问那些正在快速使用的req.query.amount
和req.query.charge