首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery验证引擎属性无法工作

jQuery验证引擎属性无法工作
EN

Stack Overflow用户
提问于 2013-10-17 05:53:34
回答 1查看 938关注 0票数 1

在发送ajax请求之前,我试图使用jQuery验证引擎来验证我的表单。但是如果表单包含错误,ajax也会发送请求。

JavaScript:

代码语言:javascript
复制
$('#addphrase').validationEngine('attach', {
    inlineValidation: false,
    promptPosition: "centerRight",
    onSuccess: function () {
        use_ajax = true;
        alert(dcd);
    },
    onFailure: function () {
        use_ajax = false;
        alert(ggg);
    }
});

$('form[name="addphrase"]').submit(function (e) {
    if (use_ajax) {
        $('#loading1').css('visibility', 'visible');
        $.get('addphrase.php', $(this).serialize() + '&ajax=1',

        function (data) {
            if (parseInt(data) == -1) {
                $("#resp1").show('slow').after('<p id="resp-mes1" style=" color:#000000; text-decoration: bold;">* Please ensure all fields are filled.","error"</p>');
            } else {
                $("#resp1").show('slow').after('<p id="resp-mes1" style=" color:#000000; text-decoration: bold;">Added successfully. Thank You...</p>');
            }
            $('#loading1').css('visibility', 'hidden');
            setTimeout("jQuery('#resp1').hide('slow');", 3000);
            setTimeout("jQuery('#resp-mes1').hide('slow');", 5000);
        });
    }
    e.preventDefault();
}
});

编辑 HTML

代码语言:javascript
复制
  <form class="form-horizontal" id="addphrase" name="addphrase" method="GET" action="">
            <div class="control-group"><label class="control-label" for="form-field-1">Phrase</label>
  <div class="controls">
  <input type="text" id="phrase" class="validate[required]" placeholder="Phrase" name="Phrase" value="" /></div></div>
  <div class="control-group"><label class="control-label" for="form-field-11">Content Here</label>
  <div class="controls">
  <textarea name="post_content"  value="" class="validate[required] autosize-transition span12" id="comment" style="overflow: hidden; word-wrap: break-word; resize: horizontal; height: 67px;"></textarea></div></div>
  <div class="space-4"></div><div class="control-group" style="float:left; margin-right:25px"><div class="controls">
  <button type="submit" class="btn btn-info">
 <i class="icon-ok bigger-110"></i>
 <input type="submit" value="" id="phsubmit" style="opacity:0">Submit</button>
 <button type="reset" class="btn"><i class="icon-undo bigger-110"></i>Reset</button></div></div>
 <div id="resp1" style="float:left; margin-top:5px"><img id="loading1" style="visibility:hidden;" src="assets/img/ajax-load.gif" width="16" height="16" alt="loading" /></div></div>
</form>

在上面的代码中,它不会显示警报,也不会附加属性,在这两种情况下,如果失败或成功的话。

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-17 05:58:42

试着使用onValidationComplete

代码语言:javascript
复制
$('#addphrase').validationEngine('attach', {
    inlineValidation: false,
    promptPosition: "centerRight",
    onValidationComplete: function (form, status) {
        if (status) {
            alert('Form submit');
            $('#loading1').css('visibility', 'visible');
            $.get('addphrase.php', $(this).serialize() + '&ajax=1',

            function (data) {
                if (parseInt(data) == -1) {
                    $("#resp1").show('slow').after('<p id="resp-mes1" style=" color:#000000; text-decoration: bold;">* Please ensure all fields are filled.","error"</p>');
                } else {
                    $("#resp1").show('slow').after('<p id="resp-mes1" style=" color:#000000; text-decoration: bold;">Added successfully. Thank You...</p>');
                }
                $('#loading1').css('visibility', 'hidden');
                setTimeout("jQuery('#resp1').hide('slow');", 3000);
                setTimeout("jQuery('#resp-mes1').hide('slow');", 5000);
            });
        }
        else
        {
            alert('Error');
        }
    },
});

读取文档

演示

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19419212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档