I am trying to update a resource using patch method. I am completely unable to do so. I am using only Node.js and no React.
I have to update the desc
field. My back-end patch request is working. The code for patch request is:
At Postman, it is working fine:
You can see the record in the DB is updated:
I need to update it through a form having a text area.
I have attached a function in my front-end JavaScript to the submit button for creating a fetch request.
Below is my form in HTML.
Here is how the button is linked with the function:
This is the error I am getting:
Here is my front-end console:
My fetch request for patch JavaScript codes:
await fetch(window.location.href, {
method: 'PATCH',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
credentials: 'include',
body: JSON.stringify({
desc: abc,
})
})
.then((response) => {
console.log(response);
return response;
})
.then((data) => {
console.log(data);
})
};