I was trying to post data to Google Sheets like this https://gist.github.com/willpatera/ee41ae374d3c9839c2d6
But after sending a request I always get an error
"Access to fetch at 'https://script.google.com/macros/s/AKfycbzTxvHO3paUHMib0SY3Lo1uIEBumEGB6z1ILgMlw3fgK6LaKOs/exec' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."
What I do wrong?
I was trying to set Mode: "no-cors" it didn't help.
formSubmit = async (e) => {
e.preventDefault();
try {
let form = this.state.data;
console.log("11111" + serialize(form, {hash: true, empty: true}));
const request = await fetch('https://script.google.com/macros/s/AKfycbzTxvHO3paUHMib0SY3Lo1uIEBumEGB6z1ILgMlw3fgK6LaKOs/exec', {
method: "POST",
data: JSON.stringify({data: this.state.data})
});
const responseData = await request.json();
console.log(
"GET ResponsePost",
"Response Body -> " + JSON.stringify(responseData));
return JSON.stringify(responseData);
} catch (e) {
console.log(e);
}
}
I want to understand why this https://gist.github.com/willpatera/ee41ae374d3c9839c2d6 works (I checked) and my code don't work.