I'm trying to fill a table with the result of a successful ajax call. I work on multiple endpoints here.
Backend (PHP):
the backend returns an Array.
Array (
[0] => Array (
[eid] => 5060529
[uid] => 494
[created] => 2020-11-10T14:23:33.903
[persnr] => 001354
[contractnr] => V-00019
[agentnr] => OL-010
[location] => 1
[client] => 1015
[validfrom] => 2020-12-01T00:00:00
[validto] => 2020-12-31T00:00:00
[isborrowed] => 1
[calweek] =>
[year] =>
)
[n] => Array(...)
)
Frontend Call:
when printing the result to the console I see the correct values itself.
$("#contractDetailBtn").on('click', function(){
let datefrom = $('input#datefrom').val();
let dateto = $('input#dateto').val();
let client = $('input#client').val();
let link = `/backend/lnk?datefrom=${datefrom}&dateto=${dateto}&client=${client}`;
console.log(link);
$.ajax({
type: 'GET',
datatype: 'html',
url: link,
success: function(result){
var table = $("#ajaxpopulate tbody");
console.log(result);
}
});
});
My try was to loop through the result values and populate the table using:
$.each(result, function(i, e){
table.append("<tr><td>"+e.eid+"</td><td>"+e.uid+"</td><td>"+e.created+"</td></tr>");
});
Which should work using json. Since I'm getting an array back I'm aparently struggeling with getting the format in a way I'd need it to. When using json_encode() in the backend I'm getting an escaped what looks to be json back. I was wondering, how I can get the result in a way I can continue to work with.
Any help would be very appreciated.