我在这里有一个函数,它以表单的形式将数据发送到Google Sheets。提示后如何执行重定向按钮?
我尝试添加window.location.href='',但它不提交数据就重定向页面。
<script>
const scriptURL = 'https://script.google.com/macros/s/AKfycbyXViROC5iq7PdxoCufOn5XfJTyArkmdQul_-pWwJ3Yc9GpwmZpO0WR2tkeVNUPA47u/exec'
const form = document.forms['google-sheet']
form.addEventListener('submit', e => {
e.preventDefault()
fetch(scriptURL, { method: 'POST', body: new FormData(form)})
.then(response => alert("Salamat po sa pag fill-out! Paki-wait nalang po ang aming call..."))
.catch(error => console.error('Error!', error.message))
document.getElementById("rider-form").reset();
window.location.href='digitsorani.net';
})
</script>
发布于 2021-07-30 23:14:49
将window.location.href = xyz
行放入promise的.then()分支。
...then(r => { alert(); reset_form(); navigate_away(); })
或者,使用异步事件处理程序并等待获取完成:
form.addEventListener('submit', async e => {
e.preventDefault();
await fetch()...;
resetFormAndNavigate();
})
https://stackoverflow.com/questions/68599967
复制相似问题