码迷,mamicode.com
首页 > Web开发 > 详细

Jquery ajax json 值回传不了

时间:2016-05-13 07:50:10      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

今天调试系统的时候,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}"); }

 

Jquery ajax json 值回传不了

标签:

原文地址:http://www.cnblogs.com/wushuaizaiza/p/5484763.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!