Ajax既不执行success方法也不执行error方法

客户端代码
$("#imgLogin").click(function () {
debugger;
var name = $("#txtName").val();
var pwd = $("#txtPwd").val();
var validate = $("#txtValidate").val();

            $.ajax({
                type: "post",
                url: "Login.asmx/UserLogin",
                data: JSON.stringify({ "_name": name, "_pwd": pwd, "_validate": validate }),
                contentType: "application/json;charset=utf-8",
                dataType:"json",
                success: function (value) {
                    if (value == "1") {
                        alert("登陆成功");
                    }
                },
                error: function () {
                    alert("系统错误");
                }
            });
        });

服务器端代码:
[WebMethod(EnableSession = true)]
public string UserLogin(string _validate,string _name,string _pwd)
{

        int flag = 0; //flag为0表示验证码错误,为1表示登陆成功,为2表示密码错误


        if (_validate.ToUpper() == Session["code"].ToString().ToUpper())
        {
            try
            {
                string _sqlStr = "select * from [user] where name='" + _name + "' and pwd='" + _pwd + "'";
                DBHelper _helper = new DBHelper("sqlConStr");
                if (_helper.ExecuteQuery(_sqlStr).Rows.Count>0)
                {
                    Session["userName"] = _name;
                    Session["userID"] = _helper.ExecuteQuery(_sqlStr).Rows[0]["ID"].ToString();
                    flag = 1;
                }
                else
                {
                    flag = 2;
                }
            }
            catch (Exception _exception)
            {
                flag = 2;
                throw _exception;
            }

        }
        else
        {
            flag = 0;
        }

        return "{'flag':" + flag.ToString() + "}";

        //return flag.ToString();
    }
查看全部
wz1091674840
wz1091674840
2014/11/14 05:32
  • ajax
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

4个回复