• 主页
  • ASP
  • .NET Framework
  • Web Services
  • VB
  • VC
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • LINQ
jtmfgfg 2014年01月12日
formValidator 和ajaxform 验证没问题,提交后直接显示处理页面 而不是本页!
数据验证没有问题, 就是提交后 直接转到我处理添加用户的页面了(就是这个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>



...全文
109 点赞 收藏 1
写回复
1 条回复

还没有回复,快来抢沙发~

发动态
发帖子
.NET技术社区
创建于2007-09-28

4.8w+

社区成员

66.8w+

社区内容

.NET技术交流专区
社区公告
暂无公告