I would like to get the HTTP status code when a form has been sent(the function for sending the form...):
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
}),
});
}
base on that status code (201 for success; else - "user must correct data) I would like to show notifications(which I am going to/and ready/ use vue-notification framework)):
if (statusCode = 201) {
*the code which show the notification for success* }
else { *the code which show the notification for correct errors* }
I would like to get the HTTP status code when a form has been sent(the function for sending the form...):
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
}),
});
}
base on that status code (201 for success; else - "user must correct data) I would like to show notifications(which I am going to/and ready/ use vue-notification framework)):
if (statusCode = 201) {
*the code which show the notification for success* }
else { *the code which show the notification for correct errors* }
Share
Improve this question
edited Jan 7, 2020 at 8:06
xx5ko
asked Oct 11, 2018 at 7:34
xx5koxx5ko
2152 gold badges4 silver badges15 bronze badges
0
1 Answer
Reset to default 4Using the then() function you can handle the response of your call. Accessing the status code is extremely simple. I added a simple snippet which you should be able to adapt for your needs.
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);
});