how to write php code inside javascript?
how to write php code inside javascript?
tomtomo
Posts: 1Questions: 1Answers: 0
im trying to pass data id from PHP inside javascript code to open data using modal, I write like this
<script>
$(document).ready(function () {
$('#table_id').DataTable({
processing: true,
serverSide: true,
ajax: 'bast-data.php',
columnDefs: [
{
"searchable": false,
"orderable": false,
"targets" : 6,
"render" : function (data, type, row) {
return `<div class="menus-table-desktop d-none d-md-flex gap-1"> <div class="ic-view"> <a href="#" data-toggle="modal" data-target="#modalView` +<?php echo $d['nomer'];?>+ `">edit</a></div>`;
}
}
]
});
});
</script>
I want to passing data from <?php echo $d['nomer'];?>
inside js code, how can I do that? something wrong when I execute my code like that, I'm using data table serverside with native php
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
This is really more a question for SO ...
https://stackoverflow.com/questions/8471945/how-can-you-use-php-in-a-javascript-function
If you need something from the server in your Javascript code please make a jQuery ajax call or a Javascript fetch call.