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.