I am facing an issue while trying to populate data from a database into an HTML table using JSON and C#.NET. The problem I am encountering is that only up to 1427 records are being displayed, and I keep getting the error message "Unexpected token <". Despite searching online for a solution, I haven't been able to resolve this issue.
Any help would be greatly appreciated.
This is what I have attempted:
//JSON
$(document).ready(function () {
bindData();
});
function bindData() {
$.ajax({
type: "POST",
url: "MyTestForm.aspx/getData",
data: "{}",
contentType: "application/json;charset=utf-8",
datatype: "jsondata",
async: "true",
success: function (response) {
var msg = eval('(' + response.d + ')');
if ($('#tblResult').length != 0) {
$("#tblResult").remove();
}
var table = "<table class='tblResult' id='tblResult'><thead><tr><th>Name</th><th>Address</th><th>Age</th><th>Action</th></tr></thead> <tbody>";
for (var i = 0; i <= (msg.length - 1) ; i++) {
var row = "<tr>";
row += '<td>' + msg[i].Name + '</td>';
row += '<td>' + msg[i].Address + '</td>';
row += '<td>' + msg[i].Age + '</td>';
row += '<td><img src="edit.png" title="Edit Record." onclick="bindRecordToEdit(' + msg[i].Id + ')" /> ';
row += ' <img src="delete.png" title="Delete Record." onclick="deleteRecord(' + msg[i].Id + ')" /></td>';
row += '</tr>';
table += row;
}
table += "</tbody></table>";
$('#divData').html(table);
$('#divData').slideDown("slow");
},
error: function (response) {
alert(response.status + ' ' + response.statusText);
}
});
}
//C#
[WebMethod]
public static string bindRecordtoEdit(int id)
{
string data = string.Empty;
try
{
using (MyTestDatabaseEntities context = new MyTestDatabaseEntities())
{
var obj = (from r in context.MstNewTests select r).ToList();
JavaScriptSerializer serializer = new JavaScriptSerializer();
data = serializer.Serialize(obj);
}
return data;
}
catch (Exception)
{
return data;
}
}