我想在发送表单后获取HTTP状态代码(发送表单的功能...):
return fetch(serviceUrl + 'Collect', {
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
Authorization: "Bearer " + DataLayer.instance.token
}),
body: JSON.stringify(
(mergedFormObjects),{
"UserId": this.oidcIdToken
}),
});
}
基于该状态码(201为成功;否则-“用户必须更正数据)我想显示通知(我将准备/准备/使用vue-notification框架):
if (statusCode = 201) {
*the code which show the notification for success* }
else { *the code which show the notification for correct errors* }
答案 0 :(得分:0)
使用then()函数,您可以处理调用的响应。访问状态码非常简单。我添加了一个简单的代码段,您应该可以适应您的需求。
return fetch(serviceUrl + 'Collect', {
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
Authorization: "Bearer " + DataLayer.instance.token
}),
body: JSON.stringify(
(mergedFormObjects),{
"UserId": this.oidcIdToken
}),
}).then(function(response){
console.log(response.status);
});