在使用JavaScript / jQuery提交表单后调用函数 [英] Call a function after a form is submitted using JavaScript / jQuery
本文介绍了在使用JavaScript / jQuery提交表单后调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在提交表单后调用一个函数,我发现我们可以在jQuery中用 .submit(处理函数())
来实现,但方法描述说,处理程序方法将在表单提交之前执行。我怎样才能真正实现这一目标?我应该在提交表单之后使用 setTimeout
还是有其他解决方案?
I want to call a function after a form is submitted, I see we can do this in jQuery with .submit(handler function())
but the method description says, the handler method will be executed just before the form is submitted. How can I actually attain this? Should I use setTimeout
after the form is submitted or is there any other solution for this?
推荐答案
$("#myFormId").on('submit', function(e) {
e.preventDefault();
$.ajax({
type: $(this).prop('method'),
url : $(this).prop('action'),
data: $(this).serialize()
}).done(function() {
doYourStuff();
});
});
这篇关于在使用JavaScript / jQuery提交表单后调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文