Datatable

Datatable

pblairpblair Posts: 9Questions: 2Answers: 0

Hello-
I am having hard time to populate data in datatable and get invalid json response, I refered to tn/1 that didn't help. Here are the issue

.aspx page
$(document).ready(function () {
$('#example').dataTable({
"ajax": "../getjosn.aspx/get_json",
"columns": [
{ "data": "u140_projectnumber" },
{ "data": ",u13f_documenttypename" }
]
});
});

I create array of objects using the below function
Public Shared Function get_json() As Object
Dim objJSONStringBuilder = New StringBuilder()

    Dim sConnection = ConfigurationManager.AppSettings("ConnectionStringprod")
    Dim objSQLConnection = New SqlConnection(sConnection)
    objSQLConnection.Open()
    Dim objSQLCommand = New SqlCommand("select u140_projectnumber,u13f_documenttypename from docversion where  u140_projectnumber is not null ", objSQLConnection)

    Dim dt As New DataTable
    Dim da As New SqlDataAdapter(objSQLCommand)
    da.Fill(dt)
    Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
    Dim rows As New List(Of Dictionary(Of String, Object))()
    Dim row As Dictionary(Of String, Object)
    'GetJSON1(dt)
    For Each dr As DataRow In dt.Rows

        row = New Dictionary(Of String, Object)()
        For Each col As DataColumn In dt.Columns
            row.Add(col.ColumnName, dr(col))

        Next
        rows.Add(row)
    Next

    Return serializer.Serialize(rows)

response.write output is valid JSON
[{"u140_projectnumber":"21234","u13f_documenttypename":"Deliverable List"},{"u140_projectnumber":"21234","u13f_documenttypename":"Deliverable List"}]

Please help. Thank you

This question has an accepted answers - jump to answer

Answers

  • pblairpblair Posts: 9Questions: 2Answers: 0

    anys tips

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    Can you link to the page in question, or use the debugger and give us the debug code please?

    Allan

  • pblairpblair Posts: 9Questions: 2Answers: 0

    Hi Allan wish you a very prosperous and happy new year 2015. The link is intranet and debug code is icapuy.

    Thanks
    Ramesh

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    The server is responding with an HTML page to the Ajax request. If you load your debug result then click the Tables tab and then Server interaction button you will see that the server is not responding with valid JSON. That is the problem.

    Allan

  • pblairpblair Posts: 9Questions: 2Answers: 0

    I see..that means something wrong with my call, right?
    $(document).ready(function () { $('#example').dataTable({ "ajax": "../getjosn.aspx/get_json", "columns": [ { "data": "u140_projectnumber" }, { "data": ",u13f_documenttypename" } ] }); });

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin
    Answer ✓

    No the call is fine. It is a problem with the server not responding with JSON.

    Allan

  • pblairpblair Posts: 9Questions: 2Answers: 0

    Thank you Allan..you are genius..

  • pblairpblair Posts: 9Questions: 2Answers: 0

    Allan-
    what does this means please. thank you
    DataTables debug bookmarklet
    An error occurred, likely due to a circular reference. Please report to support with a link.

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    It means that something somewhere has gone wrong. I would need a link to the page in question to be able to discover what.

    Allan

This discussion has been closed.