jQuery Form 插件 ajaxSubmit 回调计时
我将以下代码绑定到按钮的单击事件:
function submitForm() {
var $submitOK = false;
$('#form1').ajaxSubmit({
beforeSubmit: function() {
$submitOK = $('#form1').valid();
return $submitOK;
},
success: function(html, status) {
$("#response").text(html.substring(1, html.length - 1));
}
});
if ($submitOK) {
processForm1();
}
return $submitOK;
}
ajaxSubmit 和 beforeSubmit 回调的计时如何进行 - beforeSubmit 回调是否始终在 ajaxSubmit() 执行返回之前返回?
代码的行为符合预期 - 返回 $submitOK 等于 $('#form1').valid() 的结果,但我想确保这是确定性行为。
谢谢。
I have the following code bound to the click event of a button:
function submitForm() {
var $submitOK = false;
$('#form1').ajaxSubmit({
beforeSubmit: function() {
$submitOK = $('#form1').valid();
return $submitOK;
},
success: function(html, status) {
$("#response").text(html.substring(1, html.length - 1));
}
});
if ($submitOK) {
processForm1();
}
return $submitOK;
}
How does the timing of the ajaxSubmit and the beforeSubmit callback play out - will the beforeSubmit callback always return before execution returns from the ajaxSubmit()?
The code behaves as desired - returning $submitOK equal to the result of $('#form1').valid(), but I wanted to make sure this is deterministic behaviour.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,beforeSubmit 总是首先返回,这就是它的目的 - 它是一个预提交钩子。
Yes, beforeSubmit will always return first, that's it's purpose - it is a pre-submission hook.