Click here to Skip to main content
16,013,747 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to load values from database to html table using JSON and C#.net. I not showing the records more than 1427 and showing the error "Unexpected token <".

JavaScript
//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><table><tbody><tr><th>Name</th><th>Address</th><th>Age</th></tr></tbody></table></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 += '</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 getData()
    {
        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
        {
            return data;
        }
    }
Posted
Updated 27-Feb-16 4:05am
v3

1 solution

Quote:
Not showing records more than 1427
If everything is ok with 1426 records and you get an error with 1427, you have to check the contents of record 1427 it must contain something that break the JSon format.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900