weixin_33709219 2019-09-04 06:46 采纳率: 0%
浏览 48

Ajax表未显示

I am creating ajax table from database. my Controller returning list of object but table is not creating on the page rather it shows json string. Here is my ajax call and view:

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>

<h2>Real Time Values</h2>

<body>
<div>
    <table id="tbldata" class="tabledata">
        <tr>
            <th>Meter Number</th>
            <th>Current A</th>
            <th>Current B</th>
            <th>Current C</th>
            <th>Current N</th>
            <th>Current Avg</th>
        </tr>
    </table>

</div>
<script>
    $(function () {
        $.get(("ShowRealTimeValues", "RealTimeValues", function (data) {
            var row;
            $.each(data, function (i, v1) {
                row += "<tr><td>" + v1.MeterNumber + "</td><td>" + v1.Current_A + "</td><td>" + v1.Current_B + "</td><td>" + v1.Current_C + "</td><td>" + v1.Current_N + "</td><td>" + v1.Current_Avg + "</td></tr>"
            });
            $("#tbldata").append(row);
        }))
    })
</script>

 </body>

Here is my controller. My controller is returning list of object.

   public ActionResult ShowRealTimeValues()
    {
        DateTime time = DateTime.Now;
        var data = myDbContext.RealTimeValues.OrderByDescending(a => a.Time).Take(1).ToList();

        return Json(data, JsonRequestBehavior.AllowGet);
    }

Dont know why table is not creating. there is not any error in console.

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥30 如何降低hdfs中datanode的JVM内存用量
      • ¥15 Android URL如何转成视频/音频,可行吗?
      • ¥20 SQL数据查询,子查询
      • ¥15 c++字符串分割问题
      • ¥15 vue+uniapp
      • ¥15 android freedom
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver