asp.net-mvc - ASP.NET MVC 2 - jquery ajax 响应失败

我不明白这个错误,不要在“JsonResult Test()”中产生错误,我正在做其他项目作为ASP.NET MVC

谢谢

错误:

System.InvalidOperationException: This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.

[InvalidOperationException: This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.]
   System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context) +263733
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +10
   System.Web.Mvc.<>c__DisplayClass14.<InvokeActionResultWithFilters>b__11() +20
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +251
   System.Web.Mvc.<>c__DisplayClass16.<InvokeActionResultWithFilters>b__13() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +178
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +314
   System.Web.Mvc.Controller.ExecuteCore() +105
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +39
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +34
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +59
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8678910
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Tesis.Controllers
{
    public class AnalysisSourceDataController : Controller
    {
        //
        // GET: /AnalysisSourceData/

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult Test()
        {
            return Json(new { mymsg = "my msg" });
        }
    }
}

javascript

<script type="text/javascript">
    $(function() {
        $.getJSON("/AnalysisSourceData/Test", function(data) {
            alert(data.mymsg);
        });
    });
</script>

最佳答案

你不明白什么?这个错误几乎不能更具描述性。这是一项安全功能,可防止 JSON hijacking ,你可以像这样禁用它..

 return Json(new { mymsg = "my msg" }, JsonRequestBehavior.AllowGet);

但您应该了解 implications .

https://stackoverflow.com/questions/2350921/

相关文章:

wcf - DataContractJsonSerializer 和枚举

javascript - 如何让 AngularJS 输出转义 HTML

javascript - 从 JSON 对象中删除元素

python - 通过url获取json数据并在python中使用(simplejson)

javascript - jQuery AJAX 调用带有 JSON 返回的 PHP 脚本

json - IE9 JSON 数据 "do you want to open or save th

json - Swift 中对象的自动 JSON 序列化和反序列化

json - 是否为 null 有效 JSON(4 字节,仅此而已)

php - 如何在预先存在的 SQL 数据库之上使用 Elastic Search?

c# - 检测反序列化对象是否缺少 Json.NET 中 JsonConvert 类的字段