【发布时间】:2016-09-13 20:23:54
【问题描述】:
我希望数据采用这种格式
{"email":"s@gmail.com","password":"1"}
但是采用这种格式
{ '{"email":"s@gmail.com","password":"1"}': '' }
我的客户代码,
headers.append('Content-Type', 'application/x-www-form-urlencoded')
this.http.post(this.header1+'login', JSON.stringify(form), { headers: headers })
这个我不太清楚,有大神帮忙看看
我的后端代码,
exports.login = function( req, res ) {
console.log(req.body)
var query = 'select * from profile where email = ? and password = ?';
connection.query(query,[req.body.email,req.body.password],function(error,result,rows,fields){
if(!!error){console.log(error)
console.log('fail');
}else{
console.log(result);
res.send(result);
}
// }
});}
【问题讨论】:
-
试试
this.http.post(this.header1+'login', form, { headers: headers }) -
不要追加内容类型,也不要使用 JSON.stringify。
-
您的
form已经是 JSON。如果你字符串化,结果是一个string对象。 -
所以我应该删除 stringify?
-
删除后也没用
标签: javascript angularjs node.js express angular