表单Submit之后获得后台响应
来源:互联网 发布:vb计算机二级考试试题 编辑:程序博客网 时间:2024/06/07 08:51
第一种方式:页面初始化时直接绑定Validform
$(function(){
//部门编辑表单校验
$(".main_content form:first").Validform({
tiptype:3,
ajaxPost:true,
beforeSubmit:function(curform){
return true;
},
callback:function(data){ //alert("【"+JSON.stringify(data)+"】");
if(data.node.result == true){
var beanId = $("#info").find("input[name='formBean.beanId']").val();
$("#info").empty();
if(beanId && $.trim(beanId)!=""){
if(typeof window.refreshNode == "function"){
//刷新编辑后的节点
window.refreshNode(data.node);
}
}else{
if(typeof window.addNode == "function"){
//将新节点挂在树上
window.addNode(data.node);
}
}
}else if(data.node.result == false){
alert(data.node.message);
}else{
alert("失败了!");
}
$("#Validform_msg").hide();
}
}).addRule(
[
{ele:"[name='formBean.deptName']", datatype:"s1-30",
nullmsg:"1-30个汉字、字母、数字、下划线!", errormsg:"1-30个汉字、字母、数字、下划线!"},
{ele:"[name='formBean.orderNo']", datatype:"n1-2", nullmsg:"0-99的数字!", errormsg:"0-99的数字!"},
{ele:"[name='formBean.manager']", datatype:"/^[\u2E80-\u9FFF]{2,5}$/", nullmsg:"2-5个汉字!", errormsg:"2-5个汉字!"},
{ele:"[name='formBean.managerPhone']", datatype:"/^[0-9 ()+-]{1,30}$/",
nullmsg:"1-30个数字、+、-、(、)、空格!", errormsg:"1-30个数字、+、-、(、)、空格!"},
{ele:"[name='formBean.managerEmail']", datatype:"e,*0-30",
nullmsg:"e-mail,1-30个字符!", errormsg:"请检查e-mail格式,且长度不超过30个字符!"},
{ele:"[name='formBean.descr']", datatype:"*1-200",
nullmsg:"不超过200个字符!", errormsg:"不超过200个字符!", ignore:"ignore"}
]
);
});
第二种方式:submit方法绑定处理方式
$("form").submit(function(){
//防止重复点击,锁定登陆按钮
$(".butn").attr("disabled", "disabled").val("正在登录...");
//请求参数
var myparams = {
"user.username": $("#username").val(),
"user.password": $("#password").val(),
"captcha": $("#captcha").val(),
"logType": $("#logType").attr("value")
};
if(false == /\w{5,20}/g.test($("#username").val())){
//启用登陆按钮
$(".butn").removeAttr("disabled").val("登 录");
$("#username").focus();
$(".tips").html("请输入正确的用户名").fadeIn("normal");
}else if(false == /\w{5,32}/g.test($("#password").val())){
//启用登陆按钮
$(".butn").removeAttr("disabled").val("登 录");
$("#password").focus();
$(".tips").html("请输入正确的密码").fadeIn("normal");
}else if(false == /\d{4}/g.test($("#captcha").val())){
//启用登陆按钮
$(".butn").removeAttr("disabled").val("登 录");
$("#captcha").focus();
$(".tips").html("请输入正确的验证码").fadeIn("normal");
}else{
//异步登录
$.ajax({
url: "${pageContext.servletContext.contextPath}/userLoginWithCaptchaAction.action",
async: false,
type: "post",
data: myparams,
dataType: "json",
success: function(data){
if(data.result){
window.location="${pageContext.servletContext.contextPath}/userMainAction.action";
}else{
//启用登陆按钮
$(".butn").removeAttr("disabled").val("登 录");
$(".tips").html(data.errormessage).fadeIn("normal");
}
},
error: function(){
//启用登陆按钮
$(".butn").removeAttr("disabled").val("登 录");
$(".tips").html("无服务响应,登录失败!").fadeIn("normal");
},
});
}
return false;
});
$(function(){
//部门编辑表单校验
$(".main_content form:first").Validform({
tiptype:3,
ajaxPost:true,
beforeSubmit:function(curform){
return true;
},
callback:function(data){ //alert("【"+JSON.stringify(data)+"】");
if(data.node.result == true){
var beanId = $("#info").find("input[name='formBean.beanId']").val();
$("#info").empty();
if(beanId && $.trim(beanId)!=""){
if(typeof window.refreshNode == "function"){
//刷新编辑后的节点
window.refreshNode(data.node);
}
}else{
if(typeof window.addNode == "function"){
//将新节点挂在树上
window.addNode(data.node);
}
}
}else if(data.node.result == false){
alert(data.node.message);
}else{
alert("失败了!");
}
$("#Validform_msg").hide();
}
}).addRule(
[
{ele:"[name='formBean.deptName']", datatype:"s1-30",
nullmsg:"1-30个汉字、字母、数字、下划线!", errormsg:"1-30个汉字、字母、数字、下划线!"},
{ele:"[name='formBean.orderNo']", datatype:"n1-2", nullmsg:"0-99的数字!", errormsg:"0-99的数字!"},
{ele:"[name='formBean.manager']", datatype:"/^[\u2E80-\u9FFF]{2,5}$/", nullmsg:"2-5个汉字!", errormsg:"2-5个汉字!"},
{ele:"[name='formBean.managerPhone']", datatype:"/^[0-9 ()+-]{1,30}$/",
nullmsg:"1-30个数字、+、-、(、)、空格!", errormsg:"1-30个数字、+、-、(、)、空格!"},
{ele:"[name='formBean.managerEmail']", datatype:"e,*0-30",
nullmsg:"e-mail,1-30个字符!", errormsg:"请检查e-mail格式,且长度不超过30个字符!"},
{ele:"[name='formBean.descr']", datatype:"*1-200",
nullmsg:"不超过200个字符!", errormsg:"不超过200个字符!", ignore:"ignore"}
]
);
});
第二种方式:submit方法绑定处理方式
$("form").submit(function(){
//防止重复点击,锁定登陆按钮
$(".butn").attr("disabled", "disabled").val("正在登录...");
//请求参数
var myparams = {
"user.username": $("#username").val(),
"user.password": $("#password").val(),
"captcha": $("#captcha").val(),
"logType": $("#logType").attr("value")
};
if(false == /\w{5,20}/g.test($("#username").val())){
//启用登陆按钮
$(".butn").removeAttr("disabled").val("登 录");
$("#username").focus();
$(".tips").html("请输入正确的用户名").fadeIn("normal");
}else if(false == /\w{5,32}/g.test($("#password").val())){
//启用登陆按钮
$(".butn").removeAttr("disabled").val("登 录");
$("#password").focus();
$(".tips").html("请输入正确的密码").fadeIn("normal");
}else if(false == /\d{4}/g.test($("#captcha").val())){
//启用登陆按钮
$(".butn").removeAttr("disabled").val("登 录");
$("#captcha").focus();
$(".tips").html("请输入正确的验证码").fadeIn("normal");
}else{
//异步登录
$.ajax({
url: "${pageContext.servletContext.contextPath}/userLoginWithCaptchaAction.action",
async: false,
type: "post",
data: myparams,
dataType: "json",
success: function(data){
if(data.result){
window.location="${pageContext.servletContext.contextPath}/userMainAction.action";
}else{
//启用登陆按钮
$(".butn").removeAttr("disabled").val("登 录");
$(".tips").html(data.errormessage).fadeIn("normal");
}
},
error: function(){
//启用登陆按钮
$(".butn").removeAttr("disabled").val("登 录");
$(".tips").html("无服务响应,登录失败!").fadeIn("normal");
},
});
}
return false;
});
0 0
- 表单Submit之后获得后台响应
- 表单Form的submit事件不响应
- 非submit按钮 点击之后 表单莫名自动提交了
- jfanal form表单submit 后台getPara为空的原因。
- form表单submit提交后台无反应、前端不报错
- 在PHP增删改查里面遇到的SUBMIT表单之后的文件跳转问题
- 使用jQuery-Form做表单submit提交,获取响应json数据
- JQuery获取表单绑定的submit事件并手动调用获得返回值
- asp.net中通过form表单submit提交到后台的实例
- asp.net中通过form表单submit提交到后台的实例
- asp.net中通过form表单submit提交到后台的实例
- asp.net中通过form表单submit提交到后台的实例
- asp.net中通过form表单submit提交到后台的实例
- form 表单提交submit 和 ajax 混用可能导致后台 错误
- 如何通过submit提交form表单获取后台传来的返回值
- action,,,submit控制表单
- 一个表单 两个submit
- submit表单提交
- 螃肂肀莆袃螂芆节葿袄肈膈
- 膆薅蚁袀膈芈蝿螀膁莄薆羂
- iOS--------------浅谈视频播放
- System.in.read()的使用方法
- 莆蚂腿肈薂薈膈膁莅羇膇莃
- 表单Submit之后获得后台响应
- 莄薄袂莅薃袆袅肈芀螆袇膄
- MySQL分表实现上百万上千万记录分布存储的批量查询设计模式
- UVa #12170 Easy Climb (例题9-25)
- Android之SurfaceView学习(一)
- What can I learn right now in just 10 minutes that could be useful for the rest of my life?
- 薀袈羈葿葿袀肄芅蚁螃聿莄
- (转)调试器工作原理(2):实现断点
- Java操作剪切板