I created a controller function and tried to pass data directly to the HTML table using AJAX URL. It's difficult for me to get the URL data to the table. Below are my view and AJAX code
My Table View:
<table border='1' id="datatable"style='border-collapse: collapse;'>
<thead>
<tr>
<th>Date</th>
<th>Time</th>
</tr>
</thead>
<tbody></tbody>
</table>
The AJAX code:
<script>
var updateData = function() {
$.ajax({
url: "http://localhost/MEDAPP/public/get-post-allpatient-data/"+result,
type: 'GET',
dataType: 'json',
headers: {
'X-CSRF-TOKEN': $('meta[Time="csrf-token"]').attr('content')
},
success: function(response) {
var len = 0;
$('#userTable tbody').empty(); // Empty <tbody>
if(response['data'] != null){
len = response['data'].length;
}
if(len > 0){
for(var i=0; i<len; i++){
var id = response['data'][i].id;
var Date = response['data'][i].Date;
var Time = response['data'][i].Time;
var tr_str = "<tr>" +
"<td align='center'>" + (i+1) + "</td>" +
"<td align='center'>" + Date + "</td>" +
"<td align='center'>" + Time + "</td>" +
"</tr>";
$("#userTable tbody").append(tr_str);
}
}
},
}
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire