Json的回应并没有成功

时间:2014-03-18 17:13:13

标签: jquery asp.net-mvc json

我正在使用Jquery进行ajax调用,但看起来并不合适。

我打电话给控制员:

$.ajax({
                    url: "http://urlWithpropperParams.com",
                    cache: false,
                    type: "GET",
                    dataType: "json",
                    traditional: true,
                    success: function (result) {
                        if(result.isEdited)
                        {
                            alert('No error');
                            window.location.href = 'http://myurl.com';
                        }
                        else
                        {
                            alert('Error');
                            //html(result.message);
                        }
                    }
                });

调用该控制器并重新调整Json Object(我在其上放置一个断点,看起来很好):

public JsonResult EditAuthority(string id, bool value)
        {
...
            return Json(new { isEdited = true, message = "" });
        }

jquery ajax调用的成功部分必须做出一些东西,但什么也没发生,我在浏览器中看到没有错误。

我的错误是什么?提前谢谢。

1 个答案:

答案 0 :(得分:1)

您正在使用JSON有效负载执行HTTP GET。

  

默认情况下,ASP.NET MVC框架不允许您响应   带有JSON有效负载的HTTP GET请求。如果你需要发送JSON   响应GET,您需要明确允许该行为   使用JsonRequestBehavior.AllowGet作为Json的第二个参数   方法

来源:https://stackoverflow.com/a/8464685/84395

尝试在回复中添加AllowGet

return Json(new { isEdited = true, message = "" }, JsonRequestBehavior.AllowGet);