表单提交后如何做一个jQuery的回调? [英] How to do a Jquery Callback after form submit?
问题描述
我有一个简单的表单,其中remote = true。
这个表单实际上是一个HTML对话框,只要点击Submit按钮,它就会关闭。
现在,我需要在表单成功提交后在主HTML页面上进行一些更改。
我尝试过使用jQuery。但是这并不能确保任务在表单提交的某种形式的响应之后被执行。
$(#myform) .submit(function(event){
//在这里执行任务..
});
如何附加回调,以便我的代码只有在表单成功提交后才能执行?无论如何,要在表单中添加一些.success或.complete回调函数? 我只是做了这个 -
$ b $
$(#myform)。bind('ajax:complete',function(){
//任务做
});
完美的工作。
请参阅此api文档了解更多具体细节。
I have a simple form with remote=true.
This form is actually on an HTML Dialog , which gets closed as soon as the Submit button is clicked.
Now I need to make some changes on the main HTML page , after the form gets submitted successfully .
I tried this using jQuery. But this doesnt ensure that the tasks get performed after some form of response of the form submission.
$("#myform").submit(function(event) {
// do the task here ..
});
How do I attach a callback , so that my code gets executed only after the form is successfully submitted ? Is there anyway to add some .success or .complete callback to the form ?
I just did this -
$("#myform").bind('ajax:complete', function() {
// tasks to do
});
And things worked perfectly .
See this api documentation for more specific details.
这篇关于表单提交后如何做一个jQuery的回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!