[英]How to execute code only after the submission is done?
Here is my attempt这是我的尝试
$('#email-form').submit(function (event) {
window.location.href = url;
});
It works in some browser, but not in safari.它适用于某些浏览器,但不适用于 safari。 Apparently, this breaks this original form submission code.
显然,这破坏了原始表单提交代码。
My second attempt, this works我的第二次尝试,这有效
$('#email-form').submit(function (event) {
setTimeout(function(){
window.location.href = url;
}, 500);
});
By giving it some time, the submission code fires first, then my code runs and successfully redirects.通过给它一些时间,提交代码首先触发,然后我的代码运行并成功重定向。
What is a more robust way of writing this code (not reliant on some random timer wait)?编写此代码的更健壮的方法是什么(不依赖于一些随机计时器等待)?
我认为在每个浏览器中工作的最佳方式是👇
setTimeout(function(){document.location.href = "your link";},250);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.