seetobest 发表于 2013-3-17 16:32:20

困扰了一个下午,求高手帮忙

我做登陆的时候,想用ajax验证用户名,密码是否错误。现在通过后然后再提交表单。但是现在没有提交到验证的地址,直接提交表单了。
$(document).ready(function(){
      $("#form1").submit(function(){
            var user = $.trim($("#user").val());
            var pwd = $.trim($("#pwd").val());
            if (checkUser(user) && checkPwd(pwd)){
                $.ajax({
                        url:"http://localhost/ci/index.php/admin/login",
                        type:"get",
                        dataType:"script",
                        data:{user:user,pwd:pwd},
                        success:function(data){
                            alert(data);
                        }
                  });
            }else{
               return false;
            }

      });
    });

function checkUser(user){
      if(user==""){
            $("#user_info").html("<font color='red'>user is not null</font>");
            $("#user").focus();
            return false;
      }else{
            $("#user_info").html("");
            return true;
      }
    }
    function checkPwd(pwd){
      if(pwd==""){
            $("#pwd_info").html("<font color='red'>pwd is not null</font>");
            $("#pwd").focus();
            return false;
      }else {
            $("#pwd_info").html("");
            return true;
      }
    }

<form name="form1" id = "form1" method="post" action="">

跟屁虫 发表于 2013-3-17 18:39:23

我初步看出了两个问题,第一,你用get方式提交不合理,第二,你的ajax里没有写回调函数
页: [1]
查看完整版本: 困扰了一个下午,求高手帮忙