我目前正在尝试将我的网站表单连接到 Google 表格,但在尝试运行时收到状态 404 错误。
这是我希望在用户单击提交时发生的操作的代码:
const scriptURL = '<GoogleSheetsScriptID>';
const form = document.forms['priceForm'];
console.log(form);
form.addEventListener('submit', e => {
e.preventDefault();
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => alert("You have successfully submitted."))
.catch(error => console.error('Error!', error.message))
})
我知道我的谷歌表格脚本 ID 是正确的。问题似乎来自实际发布信息的位置,因为 404 状态错误显示在我的网站 URL 旁边(而不是 fetch 中的 google sheet 脚本 URL)。我正在 squarespace 中编写此代码,因此这可能是问题的一部分?