ajax-form


<script type="text/javascript">
//页面加载后
$(function() {
//给验证码图片添加点击事件
$("#verId,#verId2").click(function() {
//让img的src属性重新赋值为image.jsp
$("#verId").attr("src", "image.jsp?date=" + new Date());
})


//使用ajax-form插件提交登录请求
$("#loginform").ajaxForm({
beforeSubmit:function(){
$("#usernamelabelid").html("");
$("#passwordlabelid").html("");
$("#verifycodelabelid").html("");

//对表单做表单验证
var unameval = $("#unameid").val();
var pwdval = $("#pwdid").val();
var verifycodeval = $("#verifycodeid").val();
var unameflag = true;
var pwdflag = true;
var vcodeflag = true;

if(unameval.length == 0){
$("#usernamelabelid").html("请输入用户
名")
unameflag = false;
}
if(pwdval.length == 0){
$("#passwordlabelid").html("请输入密码")
pwdflag = false;
}
if(verifycodeval.length == 0){
$("#verifycodelabelid").html("请输入验证
码")
vcodeflag = false;
}
return unameflag && pwdflag && vcodeflag;
},
dataType : "json",
success : function(data) {
if (data.msgId == 1) {
window.location.href = "index.jsp";
} else if (data.msgId == 2) {
$("#passwordlabelid").html
(data.msgContent);
} else if (data.msgId == 3) {
$("#verifycodelabelid").html
(data.msgContent);
}
}
})

猜你喜欢

转载自www.cnblogs.com/moyulove/p/10896214.html