问题描述
我正在尝试在我的网站上设置 netlify 表单.我指出这个东西不适用于我的服务工作者(即使我只放置了基本的软件).没有软件,一切正常.
I'm trying to setup netlify forms on my website. I finger out that this thing doesn't work with my service worker (even when I place just basic SW). Without SW, everything works just fine.
推荐答案
感谢 Netlify 支持我解决了我的问题.那里的那些人是最好的(拥有免费帐户和他们提供的这么多帮助,直到今天真是太棒了).因为 Service Worker 劫持表单来请求,这就是 Netlify 没有捕捉到我提交的任何表单的原因.
Thnx to Netlify support I fix my problem. Those guys there are the best (having a free account and so much help from them till today is awesome). Because Service worker hijacks form to request that's why Netlify didn't catch any of my form submissions.
解决办法:您需要在联系页面上禁用 Service Worker:
Solution:You need to disable service worker on the contact page:
<script>
navigator.serviceWorker.getRegistrations().then(function(registrations)
{
for (let registration of registrations) {
registration.unregister()
}
})
</script>
从现在起禁用那个Service Worker,如果你想确保Service Worker提交后还能正常工作,只需要在重新注册Service Worker的sucsses页面添加action即可
After that service worker will be disabled from now on, if you want to be sure that service worker will work again after submission, just add action to the sucsses page where service worker will be registered again
<form name="Netlify Form" method="post" data-netlify="true" action="/send">
这篇关于Netlify 表单和服务工作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!