As mentioned in the question above, I'm trying to set a variable in my javascript as the value of the user's username. This is how my code is set up:
function submitApproveModal(){ this_file = currentFile; var approvers = ""; if(document.getElementById('approvers').checked){ approvers = '<?php $_SESSION['username'] ?>'; } approveFileAjax(this_file.uid, approvers); }
I know this is not how it works and was wondering how I could rewrite my code so that the approver equals the user's username?
P粉9967633142024-01-17 16:28:07
You just forgot about "echo":
approvers = '<?= json_encode($_SESSION['username']) ?>';
But as mentioned before, mixing Javascript and PHP is a bad idea.