在Web端发出POST请求

<form name="loginForm" action="../login.aspx" method="post">
    <label for="userName">用户名:</label><input type="text" id="userName" /> <br />
    <label for="password">密码:</label><input type="text" id="password" /> <br />
    <label for="checkNum">验证码:</label> <br />
    <button type="submit" value="Submit" id="submit">Submit</button>
</form>

<script src="../Scripts/jquery-2.1.4.min.js"></script>

<script>
    var password, userName;
    var submitBtn = $("#submit");
    var loginForm = $("loginForm");

    submitBtn.click(function () {
        userName = $("#userName").val();
        password = $("#password").val();
        $.post("../login.aspx", {userName: userName, password: password}, function (data) {
            alert(data);
        });
        return false; // 避免submit默认行为
    });
</script>

在Server端(C#)

var name = HttpContext.Current.Request["userName"];
var pwd = HttpContext.Current.Request["password"];
// Response.Write(name + "\n" + pwd + "haha,dengzhirong");

if (name == "admin" && pwd == "admin")
{
    Response.Write("Welcome to " + name + ", your password is " + pwd);
}
else
{
    Response.Write("your password doesn't match your name.");
}
}
本文作者:子匠_Zijor,转载请注明出处:http://www.dengzhr.com/others/backend/csharp/586