Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

javascript - 表单提交后如何进行Jquery回调?(How to do a Jquery Callback after form submit?)

I have a simple form with remote=true.

(我有一个带有remote = true的简单表单。)

This form is actually on an HTML Dialog, which gets closed as soon as the Submit button is clicked.

(此表单实际上位于HTML对话框上,一旦单击“提交”按钮,该对话框就会关闭。)

Now I need to make some changes on the main HTML page after the form gets submitted successfully.

(现在,我需要在表单成功提交后对主HTML页面进行一些更改。)

I tried this using jQuery.

(我尝试使用jQuery。)

But this doesn't 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 any way to add some .success or .complete callback to the form?

(有没有办法在表单中添加一些.success或.complete回调?)

  ask by geeky_monster translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just did this -

(我这样做了 - )

 $("#myform").bind('ajax:complete', function() {

         // tasks to do 


   });

And things worked perfectly .

(事情很完美。)

See this api documentation for more specific details.

(有关更多具体细节,请参阅此api文档 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...