jquery ajax validation engine not working

不打扰是莪最后的温柔 提交于 2019-12-08 05:28:28

问题


my jquery validation form is not validate ..here is the code like

    <script type='text/javascript'>
    $(document).ready(function()
    {

    $('#frm').validationEngine('validate');
    });
</script>

<div id='gap'> </div>
    <div id='main'>
        <div id='login-box'>
            <h2><span> ".HD_LOGIN." </span></h2>
            <table align='center'>
            <form id='frm' name='frm' >
                <tr> 
                    <td class='name'> <span>".LBL_USERNAME." </span> </td>
                    <td> <span> &nbsp; </span> </td>
                    <td> <input type='text' name='username' id='username' class='input validate[required]'/><input type='hidden' name='login' value='1' /></td>
                </tr>
                <tr>
                    <td id='error-show'> <span> &nbsp </span> </td> 
                </tr>
                <tr> 
                    <td class='name'> <span>".LBL_PASSWORD."</span></td>
                    <td> <span> &nbsp; </span> </td>
                    <td> <input  type='password' name='password' id='password' class='input validate[required]'/></td> 
                </tr>
                <tr>
                    <td id='error-show'><span> &nbsp; </span> </td> 
                </tr>
                <tr>
                    <td> <span> &nbsp; </span> </td>
                    <td> <span> &nbsp; </span> </td>
                    <td> <input class='chckbx' type='checkbox' name='rememberme' value='1'/> <span> ".CHCK_LOGGED." </span> </td> 
                </tr>
                <tr>
                    <td> <span> &nbsp </span> </td> 
                </tr>
                <tr> 
                    <td colspan='3' align='center'> <input type='button' name='but'  value='login' onclick=\"general_ajax1('modules/login/logincontroller.php',$('#frm').serialize())\"/></td> 
                </tr>

            </form> 

now below is custom ajax

if($("#frm").validationEngine('validate'))
       {
function general_ajax1(urld,data)
{
   $.ajax({
        type:'POST',
        url:urld,
        data:data,
        success: function(response){$('#main_content').html(response);}
        });
    }
}

回答1:


The error is in your HTML. You've put a 'form' tag inside a 'table' tag and this is not allowed.

<table align='center'>
     <form id='frm' name='frm' > <---- no!
         <tr> 

You have to do this:

<form id='frm' name='frm' > <---- no!
    <table align='center'>
        <tr> 

Remember to put the '/form' tag outside the '/table' tag in the end of file.

Also, the plugin seems to have a bug (I'm using the the master version on github). The 'validateAttribute' is undefined by default. Configure it on dom ready event.

$(function(){
   $.validationEngine.defaults.validateAttribute = "class";
});

This will put the things in order...




回答2:


<script type='text/javascript'>

    $(document).ready(function(){

        $('#frm').validationEngine();

    });

</script>

Try this way.. and then bind the inputs with class = validate[required]..




回答3:


in the initiation stage you need to to attach ValidationEngine. so try below in ready function

$(document).ready(function(){ 
    $('#frm').validationEngine('attach'); 
}); 


来源:https://stackoverflow.com/questions/11429707/jquery-ajax-validation-engine-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!