首页 > 技术文章 > Jquery ajax json 值回传不了

wushuaizaiza 2016-05-12 10:43 原文

今天调试系统的时候,MVC 框架下调用ajax 值,回传的json值获取不到,后来发现竟然是服务没开,郁闷不已,留个截图,做个纪念。

下面是调用的js方法:调试返回的值是1,不过ajax中直接跳到error方法。发现是上面的“ASP.NET 状态服务” 没开。郁闷。

 function Login() {
            if (CheckLogin()) {
                $.ajax({
                    url: "@Url.Action("Login", "Login")",
                    type: "post",
                    dataType: "json",
                    data: "UserName=" + $("#UserName").val() + "&PassWord=" + $("#PassWord").val() + "&Yzm=" + $("#Yzm").val(),
                    success: function (data) {
                        data = eval("(" + data + ")");
                        if (data.result == 0) {
                            EFSPrompt.show({ content: '验证码不正确' });
                        }
                        else if (data.result == 1)
                            window.location.href = "@Url.Action("Index", "Home")";
                        else if (data.result == 2)
                            EFSPrompt.show({ content: '用户名或密码错误' });
                        else if (data.result == 3)
                            window.location.href = "@Url.Action("ReSetPwd")?para=first";
                    },
                    error: function (e, b) {
                        alert("error");
                    }
                });

            }
        }
controller 中的方法: 

[HttpPost]
public JsonResult Login(FormCollection collection) { string UserName = SecurityRequst("UserName"); string Password = SecurityRequst("PassWord"); string Yzm = SecurityRequst("Yzm"); HttpCookie YZMCookie = Request.Cookies["YZMCookie"]; string RealYzm = YZMCookie == null ? "" : YZMCookie["yzm"];//真实的验证码 //if (Yzm != RealYzm || YZMCookie == null) // return Json("{\"result\":0}"); if (_StudentBaseInfoBO.ValidataUser(UserName, Password)) { //写日志 AddLoginLog(UserName); //if (Password =="123456")//说明是还没改密码 //{ // Session[AppConfig.ResetUserPWDKey] = UserName; // return Json("{\"result\":3}"); //} //else //{ return Json("{\"result\":1}"); //} } else return Json("{\"result\":2}"); }

 

推荐阅读