jQuery异步提交

引用jquery文件:

 <script src="JQuery/jquery.js" type="text/javascript"></script>
    <script src="JQuery/jquery.min.js" type="text/javascript"></script>
调用js:

function check()
{
    if (document.getElementById_x("username").value=="")
    {
         alert("请输入用户名")
         document.getElementById_x("username").focus();
         document.getElementById_x("username").select();
         return false;
     }
    if (document.getElementById_x("pwd").value=="")
    {
         alert("请输入密码!")
        document.getElementById_x("pwd").focus();
         document.getElementById_x("pwd").select();  
         return false;
    }
    if(document.getElementById_x("yanzheng").value == "")
    {      
          alert("请输入验证码!");
          return false;
    }
    $.post("Chuli/login.aspx",{name:$("#username").val(),pwd:$("#pwd").val(),yanzheng:$("#yanzheng").val()},resultss);
    return true;
}

//返回结果调用方法
function resultss(ee)
{
    if (ee == "error") 
    {      
        alert("用户名或者密码错误,登录失败!");       
    }
    else if(ee == "yanerror")
    {
        alert("验证码填写错误!"); 
    }
    else 
    {
        if (ee == "mansuccess")
        {
            window.location.href("HouTai/index.aspx");
        }
        else  
        {
             window.location.href("index.aspx");
        } 
   }
}

//新建异步调用页面:

后台方法:

 protected void Page_Load(object sender, EventArgs e)
    {
        string name = Request.Params["name"];
        string pwd = Request.Params["pwd"];
        string yan = Request.Params["yanzheng"].ToUpper();
        string pwds = pwd + pwd;
        UserManager uman = new UserManager();
        bool b = uman.Login(name, pwds);
        if (b==true)
        {
            Session["users"] = name;
            string yans = Session["yan"].ToString().ToUpper();
            if (!(yans.Equals(yan)))
            {
                Response.Write("yanerror");
            }
            else if (name.Equals("shiny"))
            {
                Response.Write("mansuccess");
            }
            else
            {
                Response.Write("success");
            }           
        }
        else
        {
            Response.Write("error");
        }
        Response.End();
    }

posted @ 2011-03-31 17:20  唐岗  阅读(3843)  评论(0编辑  收藏  举报