Javascript 验证登录&;使用jquery验证插件重定向到成功页面
我是一名新的jQuery脚本编写人员,在这里我将jQuery验证用于我的登录页面 如果我的登录页面成功,它必须重定向到成功页面。当我点击提交按钮时,代码与下面的代码配合良好Javascript 验证登录&;使用jquery验证插件重定向到成功页面,javascript,jquery,jquery-validate,Javascript,Jquery,Jquery Validate,我是一名新的jQuery脚本编写人员,在这里我将jQuery验证用于我的登录页面 如果我的登录页面成功,它必须重定向到成功页面。当我点击提交按钮时,代码与下面的代码配合良好 <form id="form1" name="login" method="post" action="mainpage.html"> </form> 但如果emailid=admin@admin.com&Passbrow=admin1234当我单击“提交”按钮时,它需要检查我的电子邮件ID是否正
<form id="form1" name="login" method="post" action="mainpage.html">
</form>
但如果emailid=admin@admin.com&Passbrow=admin1234当我单击“提交”按钮时,它需要检查我的电子邮件ID是否正确John@xyz.comPassbrow是password,如果两者都成功,它必须重定向,否则它必须在标签中显示错误消息
现在我得到的错误是HTTP错误405.0-方法不允许
这是小提琴
提前谢谢
问候
M由于以下原因,您的代码被破坏 1) 您将
成功
选项错误地放置在消息
选项中。success
选项是消息的兄弟,而不是子消息
messages: {
username: "Please enter a valid email address",
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
success: function (data) { // <- does not belong inside of 'messages' option
....
}
}
只需让插件按设计运行即可
- 当验证失败时,您将收到一条消息,该字段将成为焦点
- 验证通过后,表单将提交并重定向到
mainpage.html
URL,该URL由
的action=“mainpage.html”
属性指定
您的JSFIDLE已更新
您不应该在该插件中使用单击处理程序。插件中内置了一些方法,例如submitHandler
,您应该改用这些方法。除了JSFIDLE之外,还应该在OP中显示代码。
messages: {
username: "Please enter a valid email address",
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
success: function (data) { // <- does not belong inside of 'messages' option
....
}
}
success: function (data) {
if (username == 'john@xyz.com' && password == password) { // this is what the plugin does automatically when it evaluates the rules
window.location = "mainpage.html"; // this is already the 'action' part of your '<form>'
}
else {
$('#username').focus(); // Again, the plugin already does this.
}
}