Javascript 提交表单后,如何重置表单字段并向您表示成功或感谢?

Javascript 提交表单后,如何重置表单字段并向您表示成功或感谢?,javascript,html,google-sheets,Javascript,Html,Google Sheets,我在登录页上有一个简单的电子邮件订阅表单,我设法将电子邮件保存在谷歌电子表格中。我跟随了这篇文章 问题是没有任何事情表明提交成功。正在寻找一种解决方案来重置字段,并可能在不离开页面的情况下发送感谢消息 我的代码: 常量脚本URL=https://script.google.com/macros/s/AKfycbxcnv-svFYW-mhUmyzs_FhtXFWg96hOiDiD8vanzv08766Wr0/exec' const form=document.forms['submit-to-g

我在登录页上有一个简单的电子邮件订阅表单,我设法将电子邮件保存在谷歌电子表格中。我跟随了这篇文章

问题是没有任何事情表明提交成功。正在寻找一种解决方案来重置字段,并可能在不离开页面的情况下发送感谢消息

我的代码:


常量脚本URL=https://script.google.com/macros/s/AKfycbxcnv-svFYW-mhUmyzs_FhtXFWg96hOiDiD8vanzv08766Wr0/exec'
const form=document.forms['submit-to-google-sheet']
form.addEventListener('submit',e=>{
e、 预防默认值()
fetch(scriptURL,{method:'POST',body:newformdata(form)})
.then(response=>console.log('Success!',response))
.catch(error=>console.error('error!',error.message))
})
有人建议这样做(不起作用):

form.addEventListener('submit',e=>{
e、 预防默认值()
fetch(scriptURL,{method:'POST',body:newformdata(form)})
.then(response=>console.log('Success!',response),location=“yourpagehere.com)
.catch(error=>console.error('error!',error.message))
})
有人建议这样做(也没用):

form.addEventListener('submit',e=>{
e、 预防默认值()
fetch(scriptURL,{method:'POST',body:newformdata(form)})
.then(response=>{console.log('Success!',response!');window.location.href=“Thank.html”})
.catch(error=>{console.error('error!',error.message);window.location.href=“error.html”;})
})

form.reset()
form.firefevent(“reset”);
也有建议,但我不知道如何正确实现这两个功能

我添加了一个函数,在成功发布后清除输入字段并显示“成功消息”


试验
帖子成功!
常量脚本URL=https://script.google.com/macros/s/AKfycbxcnv-svFYW-mhUmyzs_FhtXFWg96hOiDiD8vanzvziGzigaWr0/exec'
const form=document.forms['submit-to-google-sheet']
form.addEventListener('submit',e=>{
e、 预防默认值()
fetch(scriptURL,{method:'POST',body:newformdata(form)})
.then(response=>console.log('Success!',Success()))
.catch(error=>console.error('error!',error.message))
})
函数成功(){
//清除表单输入
document.querySelectorAll('input')[0]。值=“”;
//显示成功消息
document.getElementById('successMessage')。style.display='block';
}

“有人建议这样做(也不起作用)”-并建议给我们实际正确的问题描述,而不是“不起作用”。非常感谢,我不得不处理s,因为我的网站实际上比我在表单上发布的内容要多,但我发现了……这就成功了!!!!!没问题。很高兴我能帮上忙!