[英]How to send form data as json in angular2
I am trying to send my form data as json but not able to do so can any one help please.... my ts, 我正在尝试以json格式发送表单数据,但无法这样做,任何人都可以帮忙...。
headers.append('Content-Type', 'application/x-www-form-urlencoded')
this.http.post(this.header1+'login', JSON.stringify(form), { headers: headers })
.subscribe(
response => {
if (response.json().error_code == 0) {
// console.log(response.json().data[0].profile_id);
if (response.json().data[0].profile_id) {
localStorage.setItem('social', JSON.stringify(response.json().data[0]));
}
this.toastr.success('Loggedin successfully');
this.router.navigate(['/demo/profile']);
}
else {
this.toastr.error('Email or Password is wrong');
}
});
}
but i am not able to see any data going to server from network 但我看不到任何数据从网络发送到服务器
i cleared it by including the following steps in my node.js 我通过在node.js中包括以下步骤来清除它
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.header('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.header('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.header('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
res.header('Access-Control-Allow-Headers', 'Content-Type, application/json');
next();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.