I use a Ajax to fill a table with data.
One field contain date and I wanted to format it different with strtotim().
How can I run php code inside my JS?
Here my Javascript snippet:
success: function (data) {
var jobs = "<table><th>Date</th><th>Time</th><th>Drive</th><th>DL</th>";
for (i in data){
jobs = jobs + "<tr><td>"+ data[i].work_date+"</td><td>"+data[i].work_time +"</td><td>"+data[i].work_driveto+"</td><td>"+data[i].work_text+"</td></tr>";
}
jobs = jobs + "</table>";
document.getElementById("jobs").innerHTML = jobs;
}
Here is what I would like to have:
success: function (data) {
var jobs = "<table><th>Date</th><th>Time</th><th>Drive</th><th>DL</th>";
for (i in data){
jobs = jobs + "<tr><td>"+ <?php echo date('d.m.Y', strtotime(data[i].work_date)); ?>+"</td><td>"+<?php echo date('H:i', strtotime(data[i].work_time)); ?> +"</td><td>"+data[i].work_driveto+"</td><td>"+data[i].work_text+"</td></tr>";
}
jobs = jobs + "</table>";
document.getElementById("jobs").innerHTML = jobs;
}