Ajax调用成功后jQuery验证问题
Ajax call after successfull jQuery validation issue
从这里使用RSV jQuery验证。
真的卡在一个地方了。我为这个插件编写了自定义错误处理程序(阅读文档,这是允许的),现在它显示错误,并逐个关注确切的字段,然后在验证结束时,如果没有错误,我的自定义处理程序return (errorInfo.length == 0) ? true : false;
返回true。问题是,在此rsv直接发送表单数据到PHP。但是我想在成功验证后触发Ajax函数。我为"oncomplete"事件写了另一个函数wellDone()
,似乎插件根本没有触发oncomplete函数。请帮我解决这个问题。
$(document).ready(function() {
$("#signup_form").RSV({
onCompleteHandler: wellDone,
customErrorHandler: errorHandler,
rules: signup_rules
});
});
function errorHandler(f, errorInfo)
{
for (var i=0; i<errorInfo.length; i++)
{
// errorInfo[i][0] contains the form field node that just failed the validation, e.g.
errorInfo[i][0].focus();
// errorInfo[i][1] contains the error string to display for this failed field, e.g.
$.notifyBar({
cls: "error",
html: errorInfo[i][1]
});
}
return (errorInfo.length == 0) ? true : false;
}
function wellDone(){
signUp();
}
var signup_rules = [
<some validation rules>...
]
如果您使用customErrorHandler
,那么实际上onCompleteHandler
将永远不会被调用。当errorInfo.length == 0
.
customErrorHandler
末尾自己调用它。可能您应该缓存从customErrorHandler函数返回的true或false值在一个变量中(该变量可用于所有正在进行ajax调用的函数),并使用它来确定是否触发ajax调用。
你的customerrorhandler应该总是返回"false",而不是" balabala ? "True: false"
这是为那些熟悉javascript的人准备的对如何呈现错误有更多的控制。它让你定义您自己的自定义函数,将错误列表传递给它这发生在表单提交上。这里有一个简单的例子提醒大家依次是错误。注意:两个函数参数必须按顺序设置正确传递错误信息
customErrorHandler:
$(document).ready(function() {
$("#demo_form1").RSV({
customErrorHandler: myReturnFunction,
rules: [
// ...
]
}); });
/**
* @param f the form node
* @param errorInfo an array of arrays. Each sub-array has two elements: the field node and the error message.
*/
function myReturnFunction(f, errorInfo) {
for (var i=0; i<errorInfo.length; i++)
{
// errorInfo[i][0] contains the form field node that just failed the validation, e.g.
errorInfo[i][0].focus();
errorInfo[i][0].style.color = "red";
// errorInfo[i][1] contains the error string to display for this failed field, e.g.
alert(errorInfo[i][1]);
}
return false; // always return false! Otherwise the form will be submitted**
}
看到最后一行代码及其注释了吗?总是返回false:-)
相关文章:
- Javascript验证问题
- CRM身份验证问题
- 获取json结果的身份验证问题
- JS表单验证问题
- 如何在窗体中使用多个按钮解决验证问题
- 带有jquery验证问题的php表单
- Google UiApp中的Google Apps脚本验证问题
- 骨干模型验证问题
- IPV6验证问题
- PHP表单,MailFoction和Google reCaptcha验证问题
- 我在登录页面上遇到php验证问题
- jQuery,CORS,JSON(不带填充)和身份验证问题
- JQuery 使用引导 col-x 时验证问题
- 如何清除两个提交按钮的验证问题
- Facebook标签/页面身份验证问题:getLoginStatus总是返回not_authorized
- asp.net JavaScript 验证问题
- 主干验证问题
- 表单验证问题(Javascript)
- jquery ajax 调用表单身份验证问题
- 指令中的角度验证问题