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的原因 

  • 相关阅读:
    psy & vr
    psy 2
    psy
    linux c中select使用技巧
    hostent h_addr_list
    gethostbyname() -- 用域名或主机名获取IP地址
    c_select 调用参数说明
    [NYOJ 737] 石子合并(一)
    [HDU 1059] Dividing
    [HDU 1789] Doing Homework again
  • 原文地址:https://www.cnblogs.com/mww-NOTCOPY/p/12341768.html
Copyright © 2011-2022 走看看