我在从http POST获取参数时遇到问题,当我使用标题时,我无法从对象中获取属性,但是当我对其进行评论并且不使用它时,我可以从req.body.type获取它们等等......
//Angular
let options = new RequestOptions({ headers:headers});
let postParams = {
tipo: this.Tipoid,
numid: this.numid,
nombres: this.noms,
apellidos: this.apellidos,
edad:this.edad,
genero:this.genero,
cargo:this.cargo }
// let headers = this.getHeaders();
console.log(postParams);
this.http.post("http://localhost:3000/api/empleados", postParams,options).
map(res => res.json()).subscribe(data => {
this.posts = data;
console.log(this.posts);
let alert = this.alertCtrl.create({
title: 'Resultado',
subTitle: this.posts.message,
buttons: ['OK']
});
alert.present();
});;
}
和Node.js代码
EmpleadosRoute.post(isAuth,(req, res) => {
// Create a new instance of the model
var empleado = new Empleado();
console.log(req.body);
当我使用标题时,我得到这样的回复......
{ '{\n "data": {\n "tipo": "CC",\n "numid": "343",\n "nombres": "da",\n "apellidos": "",\n "edad": "",\n "genero": "",\n "cargo": ""\n }\n}': '' }
但是当我评论标题时,我得到的回应如下:
{"data": "tipo": "CC", "numid": "343", "nombres": "da", "apellidos": "", "edad": "", "genero": "", "cargo": "": '' }