Wierd happenings with source.
Wierd happenings with source.
I have an ajax call to a php files which returns formatted info.
url = "includes/getattachedData.php";
data = "callInfo="+localStorage.getItem("callInfo");
$.ajax({
url : url,
data : data,
type :"POST",
success : function(returned){
var AD = returned.trim();
console.log(AD);
$('#example').DataTable( {
data: AD,
columns: [
{ title: "Event" },
{ title: "Occurred At" },
{ title: "Call ID" },
{ title: "EventID." },
{ title: "Key" },
{ title: "Value" }
]
} );
},
The info returned looks like perfectly formatted. And if i cut and paste it from the console and put it as
var AD = [[..... etc it works perfectly. But if i try to use it as the returned value from the ajax it gives me "DataTables warning: table id=example - Requested unknown parameter '1' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4"
[[ "Added", "2018-02-23T03:33:40.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:33:40.000Z_1519356820_MLN3V193DT0TTC9BBLFCP22RT400003H","PhoneNumber","6727" ],
[ "Added", "2018-02-23T03:33:40.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:33:40.000Z_1519356820_MLN3V193DT0TTC9BBLFCP22RT400003H","IW_CaseUid","d500c1fd-d75e-4e0e-b874-6544f0584301" ],
[ "Added", "2018-02-23T03:33:40.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:33:40.000Z_1519356820_MLN3V193DT0TTC9BBLFCP22RT400003H","IW_BundleUid","70dacc69-b791-4817-8480-c45534063b83" ],
[ "Added", "2018-02-23T03:33:50.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:33:50.000Z_1519356830_MLN3V193DT0TTC9BBLFCP22RT400003H","RTenantDBID","1" ],
[ "Added", "2018-02-23T03:33:50.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:33:50.000Z_1519356830_MLN3V193DT0TTC9BBLFCP22RT400003H","ServiceObjective","" ],
[ "Added", "2018-02-23T03:33:50.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:33:50.000Z_1519356830_MLN3V193DT0TTC9BBLFCP22RT400003H","CustomerSegment","default" ],
[ "Added", "2018-02-23T03:33:50.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:33:50.000Z_1519356830_MLN3V193DT0TTC9BBLFCP22RT400003H","ServiceType","default" ],
[ "Added", "2018-02-23T03:33:50.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:33:50.000Z_1519356830_MLN3V193DT0TTC9BBLFCP22RT400003H","RVQDBID","" ],
[ "Added", "2018-02-23T03:33:53.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:33:53.000Z_1519356833_MLN3V193DT0TTC9BBLFCP22RT400003H","GSIP_RECORD","ON" ],
[ "Added", "2018-02-23T03:33:53.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:33:53.000Z_1519356833_MLN3V193DT0TTC9BBLFCP22RT400003H","GSIP_REC_FN","MLN3V193DT0TTC9BBLFCP22RT400003H_2018-02-23_03-33-53" ],
[ "Deleted", "2018-02-23T03:34:03.000 0000","MLN3V193DT0TTC9BBLFCP22RT400003H","2018-02-23T03:34:03.000Z_1519356843_MLN3V193DT0TTC9BBLFCP22RT400003H","GSIP_RECORD","ON" ]];
I'm thinking because it is expecting an array but only getting text which looks like an array.
Any help greatly appreciated.
This question has an accepted answers - jump to answer
Answers
Hi @asystemsaus ,
There's two ways to go - either change the server so that it sends an object rather than a string, or, change the client to convert the string to an array of arrays (you can use
JSON.parse()
) to do that,Cheers,
Colin
Hi @colin,
As you correctly pointed out the answer was to correctly format in the php script and then use JSON.parse in the javascript to populate the table. Works like a charm.
Much appreciated.