jQuery ajax验证引擎不起作用 [英] jquery ajax validation engine not working
本文介绍了jQuery ajax验证引擎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的jquery验证表单未验证..这是类似的代码
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> </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>   </span> </td>
</tr>
<tr>
<td class='name'> <span>".LBL_PASSWORD."</span></td>
<td> <span> </span> </td>
<td> <input type='password' name='password' id='password' class='input validate[required]'/></td>
</tr>
<tr>
<td id='error-show'><span> </span> </td>
</tr>
<tr>
<td> <span> </span> </td>
<td> <span> </span> </td>
<td> <input class='chckbx' type='checkbox' name='rememberme' value='1'/> <span> ".CHCK_LOGGED." </span> </td>
</tr>
<tr>
<td> <span>   </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>
下面是自定义Ajax
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);}
});
}
}
推荐答案
该错误在您的HTML中.您已将表单"标签放入表格"标签内,这是不允许的.
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>
您必须这样做:
<form id='frm' name='frm' > <---- no!
<table align='center'>
<tr>
请记住将'/form'标记放在文件末尾的'/table'标记之外.
Remember to put the '/form' tag outside the '/table' tag in the end of file.
此外,该插件似乎有一个错误(我在github上使用的是主版本). 默认情况下,"validateAttribute"是未定义的.在dom ready事件上对其进行配置.
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...
这篇关于jQuery ajax验证引擎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文