如何在使用jquery提交表单后使用Success,Failure回调函数 [英] How to use Success, Failure callback function after form submission using jquery

查看:87
本文介绍了如何在使用jquery提交表单后使用Success,Failure回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jquery提交我的mvc表格

$(#form1)。submit();

i想要使用回调函数来表示成功和失败提交。

告诉我完美的解决方案。我可以在表单提交后使用回调函数。

解决方案

(#form1)。submit ();

i希望在表单提交后使用回调函数成功和失败。

告诉我完美的解决方案。我可以在表单提交后使用回调函数。

你不能,这个同步提交表格。这意味着您更容易接受回发,如果您尝试使用 return false event.preventDefault()表单提交被取消。就那么简单!这就是为什么,即使你尝试过,也无法让它发挥作用。 :)



由于这是一个你正在谈论的jQuery函数,请在 .submit() [ ^ ]。不要与函数中的处理程序混淆。该函数被调用时执行该处理程序,它与服务器的失败响应成功无关。



处理表单的成功或失败事件(或任何请求)您需要有异步请求。例如,Ajax是满足这种需求的非常有效的候选者。在ajax请求中,您可以处理成功或失败(错误)事件。



 


.ajax({
url:' your-action-url' // 任意网址
数据:


m using jquery to submit my mvc form
$("#form1").submit();
i want to use callback function for success and failure after form submission.
tell me perfect solutions.how i can use callback functions after form submission.

解决方案

("#form1").submit();
i want to use callback function for success and failure after form submission.
tell me perfect solutions.how i can use callback functions after form submission.


You cannot, this submits the form synchronously. Which means that you are more exposed to postback and if you try to use return false or event.preventDefault() form submission is cancelled. Simple as that! That is why, you cannot get it to work even if you tried. :)

Since this is a jQuery function you are talking about, please read more about it here on .submit() on jQuery API[^]. Do not get confused with the handler in the function. That handler is just executed when this function gets called, it has nothing to do with success of fail response from servers.

To handle the success or fail events for forms (or any requests) you need to be having an asynchronous request. Ajax, for example, is a very valid candidate for this need. In ajax requests you get to handle the success or fail (error) events.


.ajax({ url: 'your-action-url', // Any URL data:


这篇关于如何在使用jquery提交表单后使用Success,Failure回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆