尽管ClientValidation失败,为什么仍发送XmlHttpRequest? [英] Why XmlHttpRequest is sent though ClientValidation is failed?

查看:55
本文介绍了尽管ClientValidation失败,为什么仍发送XmlHttpRequest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

页面上有很多AJAX表单,单击按钮后,我需要全部提交.常规form.each(function(index,form){$(form).submit();})对我不起作用,因为这样最终只会提交最后一个表单.因此,我需要通过$提交它们.ajax(...).但是我想仅在表单有效时启用提交,


在"submitForms"上,单击功能"submitTest".
如果形式为有效,则将从jQuery文档中调用" submitHandler ".
因此,验证有效,并且如果表单为 INVALID ,则不会调用" submitHandler ".但是,尽管未调用" submitHandler ",但仍会发送XmlHttpRequest.

我在哪里犯错?
谢谢

I have many AJAX forms on the page and on button click I need to submit them all. Regular forms.each(function (index, form) { $(form).submit();} won''t work for me because in this way ONLY the last form will be submitted eventually. Therefore, I need submit them via $.ajax(...). But I want to enable submit ONLY and ONLY if form is VALID


On "submitForms" click the fucntion "submitTest" is invoked.
From jQuery documentation "submitHandler" would be called if form is VALID.
So, the validation works and "submitHandler" is NOT invoked if form is INVALID. BUT, the XmlHttpRequest is sent anyway, though "submitHandler" isn''t invoked.

Where I make mistake?
Thank you

<% using (Ajax.BeginForm("FormPost", "Customer", null, new AjaxOptions() { HttpMethod = "POST" }, new { @class = "form-container" }))
           { %>
        
                <%: Html.TextAreaFor(m => m.Name, new { width = 440, height = 100 })%>
                 <input type="button" value="submitForms" />
        <% }%>


<script type="text/javascript">
function submitTest()
{
    var forms = $(".form-container");
    
    forms.each(function (index, form) {
        $(form).validate({
             submitHandler: function (form) {
                     $.ajax(
                     { 
                        ....
                     });
             }
        });
    });

    forms.each(function (index, form) {
         $(form).submit();
    });
}
</script>

推荐答案

(form).submit();}对我不起作用,因为这样只能最终提交最后一个表单.因此,我需要通过
(form).submit();} won''t work for me because in this way ONLY the last form will be submitted eventually. Therefore, I need submit them via


.ajax(...)提交它们.但是我想仅在表单有效时启用提交,


在"submitForms"上,单击功能"submitTest".
如果表单为有效,则将从jQuery文档中调用" submitHandler ".
因此,验证有效,并且如果表单为 INVALID ,则不会调用" submitHandler ".但是,尽管未调用" submitHandler ",但仍会发送XmlHttpRequest.

我在哪里犯错?
谢谢

.ajax(...). But I want to enable submit ONLY and ONLY if form is VALID


On "submitForms" click the fucntion "submitTest" is invoked.
From jQuery documentation "submitHandler" would be called if form is VALID.
So, the validation works and "submitHandler" is NOT invoked if form is INVALID. BUT, the XmlHttpRequest is sent anyway, though "submitHandler" isn''t invoked.

Where I make mistake?
Thank you

<% using (Ajax.BeginForm("FormPost", "Customer", null, new AjaxOptions() { HttpMethod = "POST" }, new { @class = "form-container" }))
           { %>
        
                <%: Html.TextAreaFor(m => m.Name, new { width = 440, height = 100 })%>
                 <input type="button" value="submitForms" />
        <% }%>


<script type="text/javascript">
function submitTest()
{
    var forms =


(.form-container"); form.each(function(index,form){
(".form-container"); forms.each(function (index, form) {


这篇关于尽管ClientValidation失败,为什么仍发送XmlHttpRequest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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