首页 > 代码库 > ASP.NET MVC+JQuery母版页的Ajax提交问题

ASP.NET MVC+JQuery母版页的Ajax提交问题

<pre name="code" class="javascript">Ajax内容:
$(document).ready(function () {
            $(function () {
                $("#submit").click(function () {
                    var name = $("#log").val();
                    var pwd = $("#pwd").val();

                    if (name.length == 0) {
                        alert("请输入用户名!");
                    }
                    else if (pwd.length == 0) {
                        alert("请输入密码!");
                    }
                    else {
                        $.post("../../Content/Handler.aspx", { mName: name, mPwd: pwd }, function (data) {
                            if (data =http://www.mamicode.com/= "right") {>
再建一个Handler.aspx页面,后台写:
<pre name="code" class="csharp">protected void Page_Load(object sender, EventArgs e)
        {
            string name = Request.Form["mName"].ToString();
            string pwd = Request.Form["mPwd"].ToString();
            if (name == "hu")
            {
                Response.Write("right");
                Response.End();
            }
            else
            {
                Response.Write("用户名或密码错误!");
                Response.End();
            }
        }

注意母版页的路径问题,最好将Handler.aspx页面放在Contents目录下

ASP.NET MVC+JQuery母版页的Ajax提交问题