formValidator 和ajaxform 验证没问题,提交后直接显示处理页面 而不是本页!

jtmfgfg jtmfgfg 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
数据验证没有问题, 就是提交后 直接转到我处理添加用户的页面了(就是这个useraddHandler.ashx)

表单提交我用的jQuery Form Plugin

应该是俩个插件哪块没整对。。求指点!!!





$(document).ready(function () {
$.formValidator.initConfig({ theme: "ArrowSolidBox", submitOnce: true, formID: "myFormId",
onError: function (msg) { alert(msg); },
submitAfterAjaxPrompt: '有数据正在异步验证,请稍等...'
});
$("#userid").formValidator({ onShowFixText: "3~12个非空字符", onCorrect: "该用户名可以注册" }).inputValidator({ min: 3, max: 12, onError: "你输入的用户长度不正确,请确认" }).regexValidator({ regExp: "username", dataType: "enum", onError: "用户名格式不正确" })
.ajaxValidator({
// dataType : "String",
async: true,
url: "usercheckHandler.ashx",
success: function (data) {
if (data == "0") return true;
return "该用户名不可用,请更换用户名";
},
buttons: $("#button"),
error: function (jqXHR, textStatus, errorThrown) { alert("服务器没有返回数据,可能服务器忙,请重试" + errorThrown); },
onError: "该用户名已存在!",
onWait: "正在进行合法性校验,请稍候..."
});
$("#passwd1").formValidator({ onShowFixText: "6~16个字符,包括字母、数字、特殊符号,区分大小写" }).inputValidator({ min: 6, max: 16, empty: { leftEmpty: false, rightEmpty: false, emptyError: "密码两边不能有空格" }, onError: "密码长度错误,请确认" }).passwordValidator({ compareID: "us" });
$("#passwd2").formValidator({ onShowFixText: "请再次输入密码", onCorrect: "密码一致" }).inputValidator({ min: 1, empty: { leftEmpty: false, rightEmpty: false, emptyError: "密码两边不能有空格" }, onError: "重复密码不能为空" }).compareValidator({ desID: "passwd1", operateor: "=", onError: "2次密码不一致" });
$("#username").formValidator({ onShow: "请输入姓名", onFocus: "姓名不能为空", onCorrect: "姓名合法" }).inputValidator({ min: 1, onError: "姓名不能为空,请确认" });
var options = {
target: null, // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback
// other available options:
// url: "useraddHandler.ashx"; override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit

// $.ajax options can be used here too, for example:
//timeout: 3000
};
$('#myFormId').submit(function () {

$(this).ajaxSubmit(options);
return true;
});
function showResponse(responseText, statusText) {

if (responseText == '0') {
alert('用户添加失败,请重新添加!');
$('#myFormId').clearForm();
}
else {
alert('用户添加成功!');
$('#myFormId').clearForm();
}

}
function showRequest(formData, jqForm, options) {
$('#myFormId').ajaxForm({ beforeSubmit: formValidator });
}
});






<form class="form-horizontal" id="myFormId" action="useraddHandler.ashx">
<div class="control-group">
<label class="control-label" for="inputEmail">用户名</label>
<div class="controls">
<input type="text" id="userid" placeholder="text" runat="server">    </div> </div>
<div class="control-group">
<label class="control-label" for="inputPassword">姓名</label>
<div class="controls">
<input type="text" id="username" placeholder="text" runat="server">  
</div> </div>
<div class="control-group">
<label class="control-label" for="inputPassword">密码</label>
<div class="controls">
<input type="text" id="passwd1" name="passwd1" placeholder="Password" runat="server">
</div> </div>
<div class="control-group">
<label class="control-label" for="inputPassword">重复密码</label>
<div class="controls">
<input type="text" id="passwd2" name="passwd2" placeholder="Password" runat="server">
</div> </div>

<div class="control-group">
<div class="controls">
<div class="form-actions">
<input id="bntadd" type="submit" value="添加用户" class="btn btn-primary" />
</div>
</div>
<div class="alert hide " id="myuserid" aria-hidden="true">
<button data-dismiss="alert" class="close" type="button">×</button>
<strong>提示!</strong>用户名必填!
</div>
</div></form>



...全文

相关推荐

formvalidator验证插件中有关ajax验证问题

jquery formvalidator插件是不错的国产验证插件了,做点普通的校验也是很方便的,但最近遇到个问题,发现如果表单整个表单是AJAX提交时,就不能按传统的做法了

weixin_38674115

高校技术转移办公室人员在推广科技成果时,如何解决技术推介材料制作繁琐、缺乏专业性的问题?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

利用 MATLAB 仿真均匀平面波极化的传播图像(线极化,圆极化).zip

1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。

海神之光

产业园区运营如何通过智能手段精准匹配产业需求与技术供给?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

政府科技管理者在推动科技成果转化过程中,如何有效解决供需信息匹配不精准的问题?.docx

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN
评论 1
收藏 已收藏
分享
返回顶部
jtmfgfg
.NET社区 62,272 成员 668,968 内容