zoukankan      html  css  js  c++  java
  • Ajax请求成功但是一直进入error 之 序列化类型为“System.Reflection.RuntimeModule”的对象时检测到循环引用。解决方案

    前端代码:

    $.ajax({
         url: $("#dataMain").attr("data-url"),
         type: "GET",
         dataType: "json",
         timeout: 3000,
         data: data,
         success: function (res) {
              console.log(res);
          },
          error: function (res) {
               console.log(res);
          }
    });

    后端代码:

     [HttpGet]
     public JsonResult Test1() 
     {
         var sql = string.Format(@"SELECT * FROM RELEASE ");
    DataTable dataTable
    = GlobalContext.Resolve<ISource_Web_SQLHelper>().GetDataSet(sql, "你的数据库链接串").Tables[0]
    return Json(dataTable, JsonRequestBehavior.AllowGet); }

    结果:总是跑到 Ajax的 error 方法中

    error: function (res) {
        console.log(res);
    }

    解决方案一:后端代码将 dataTable 先经过下列操作再返回。

    JsonSerializerSettings setting = new JsonSerializerSettings()
    {
        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
    };
    
    var data = JsonConvert.SerializeObject(dataTable, setting);
    return Json(data, JsonRequestBehavior.AllowGet);

    解决方案二:后端代码将 dataTable 转化成 List 再返回 。

    var data=dataTable.AsEnumerable().ToList();
    return Json(data, JsonRequestBehavior.AllowGet);

    Java: Ajax请求成功但是一直进入error的原因 

  • 相关阅读:
    实验三
    第六七章读后感
    0415评论
    0414-复利计算
    实验8 201306114104彭得源
    实验7 201306114104彭得源
    实验6 201306114104彭得源
    android实验五201306114104彭得源
    android实验四201306114104彭得源
    实验五 04彭得源
  • 原文地址:https://www.cnblogs.com/mww-NOTCOPY/p/12341768.html
Copyright © 2011-2022 走看看