I have a php script that I'm trying to trigger with Javascript. I'm trying to set the URL dynamically with php using a variable but am not having any luck, does anyone know how I should approach this?
<a href="#" onclick="return getOutput();">Click here</a>
<?php $update_url = 'https://' . $_SERVER['SERVER_NAME'] . '/xyz.php'; ?>
function getOutput() {
getRequest(
var str = "<?php echo $update_url ?>", // URL for the PHP file
drawOutput, // handle successful request
drawError // handle error
);
return false;
}
var str =getRequest()function, so you cannot havevar str =there. You could define it some where else or directly pass itvaris a statement, not an expression. You can't use statements as arguments.