ajax提交表单到servlet,又是这个谜之BUG……Ajax提交表单,提交前验证了数据,提交到servlet后就为Null了...

先来JSP表单代码

登 录

还没有账户? 立刻创建

再是JS代码和Ajax$(function(){

$("#logon").click(function(){

check_register();

})

$("#login").click(function(){

var name=$("#loginUserName").val();

var pass=$("#loginUserPass").val();

var CodeCoreInput=$("#CodeCoreInputA").val();

if(name!="" && name!=" "){

if (pass!="" && pass!=" ") {

if (CodeCoreInput!="" && CodeCoreInput!=" ") {

Login();

}else{

$("#hello b").html("验证码不能为空");

setTimeout(function(){

$("#hello b").html("Hello! Please Login");

},2000);

$("#login_form").removeClass('shake_effect');

setTimeout(function()

{

$("#login_form").addClass('shake_effect')

},1);

}

}else{

$("#hello b").html("密码不能为空");

setTimeout(function(){

$("#hello b").html("Hello! Please Login");

},2000);

$("#login_form").removeClass('shake_effect');

setTimeout(function()

{

$("#login_form").addClass('shake_effect')

},1);

}

}

else

{

$("#hello b").html("用户名不能为空");

setTimeout(function(){

$("#hello b").html("Hello! Please Login");

},2000);

$("#login_form").removeClass('shake_effect');

setTimeout(function()

{

$("#login_form").addClass('shake_effect')

},1);

}

})

$('.message a').click(function () {

$('form').animate({

height: 'toggle',

opacity: 'toggle'

}, 'slow');

});

})

最后是servlet代码public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

PrintWriter out = response.getWriter();

Object A = request.getParameter("loginUserName");

Object B = request.getParameter("loginUserPass");

Object C = request.getParameter("CodeCoreInputA");

HttpSession session = request.getSession();

Object Code = session.getAttribute("Code");

if (C!=Code) {

out.print("Code Over");

}else{

User_Logic UL = new User_Logic();

String val = UL.login(A, B);

out.print(val);

}

}

function Login() {

alert($(".login-form").serialize());

$.ajax({

type : "POST",

url : "Core_UserLogin",

data: $(".login-form").serialize(),

success : function(data) {

if(trim(data)=="DBA Over"){

$("#hello b").html("数据库异常");

setTimeout(function(){

$("#hello b").html("Hello! Please Login");

},1500);

$("#CodeCoreInputA").val("");

loing();

}else if(trim(data)=="Account OR PassWord Over"){

$("#hello b").html("用户名或密码错误");

setTimeout(function(){

$("#hello b").html("Hello! Please Login");

},1500);

$("#loginUserName").val("");

$("#loginUserPass").val("");

$("#CodeCoreInputA").val("");

loing();

}else if(trim(data)=="Code Over"){

$("#hello b").html("验证码错误");

setTimeout(function(){

$("#hello b").html("Hello! Please Login");

},1500);

$("#CodeCoreInputA").val("");

loing();

}else if(trim(data)=="PassIsNull"){

$("#hello b").html("欢迎回来"+data);

setTimeout(function(){

$("#hello b").html("正在跳转");

},1500);

}

}

});

}

取值全部为空,使用GET可用成功,但只要用到POST就死了……以前都是关机重启就好了,这次关了几次还是这样

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值