Data source as javascript variable not working

Data source as javascript variable not working

mikengstrommikengstrom Posts: 2Questions: 1Answers: 0

Hi there,

I'm having problems getting my data from a xhttp.responseText.

I have my json coming back as which I'm assign to a variable tbldata

'[{"LOTTERY":"CFC","DRAW_NO":"93","PAYMENT_TYPE":"CC","SALE_DATE":"15\/06\/2020","ORDER_ID":"00005500","REFERENCE":"Jocko Brocks","AMOUNT":"70"}]'

In my data table call I'm using

"data": tbldata,
            "columns": [
                { "data": "LOTTERY" },
                { "data": "DRAW_NO" },
                { "data": "PAYMENT_TYPE" },
                { "data": "SALE_DATE" },
                { "data": "ORDER_ID" },
                { "data": "REFERENCE" },
                { "data": "AMOUNT" }
            ],

But I'm getting 2 errors
"DataTables warning: table id=datatable - Requested unknown parameter 'LOTTERY' for row 0, column 0. "
"DataTables warning: table id=datatable - Requested unknown parameter 'AMOUNT' for row 0, column 6. "

But if I take that same string and replace tbldata with it everything works correctly.

    "data" : [{"LOTTERY":"CFC","DRAW_NO":"93","PAYMENT_TYPE":"CC","SALE_DATE":"15\/06\/2020","ORDER_ID":"00005500","REFERENCE":"Jocko Brocks","AMOUNT":"70"}],
                "columns": [
                    { "data": "LOTTERY" },
                    { "data": "DRAW_NO" },
                    { "data": "PAYMENT_TYPE" },
                    { "data": "SALE_DATE" },
                    { "data": "ORDER_ID" },
                    { "data": "REFERENCE" },
                    { "data": "AMOUNT" }
                ],

Anything glaringly obvious whats' going on here?

Cheers

Answers

  • mikengstrommikengstrom Posts: 2Questions: 1Answers: 0

    Seem to have it working now

    Needed to JSON.parse(tbldata); and call "aoColumns":

    hope this might help someone. Cheers

This discussion has been closed.