What I am trying to do is to load data-id in drop-down menu when I click the list item, it need retrieve the data from db and append in table.
So far, I loaded the data id in drop-down menu and while on-click the list I send ajax call to retrieve data.
My code (controller page):
public function calcList($id)
{
$designId=design::find($id);
$design = design::select( `design_no`, `design_name`, `weight_length`, `quantity`, `design_image`, `des2`, `des3`, `des4`, `des5`, `des6`, `des7`)->where('id','=',$designId);
// return Response::json(array('datas' => $design));
// return response()->json(['data'=>$design]);
return Response::json($design);
}
Ajax Request:
$(document).ready(function() {
$('.designList').click(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var id =($(this).attr("data-id"));
$.ajax({
type:"POST",
url:"/calc_list/"+id,
success : function(results) {
console.log(results);
}
});
});
});
On the console log, the results print like {..}
How to built the json to table?