So I have data that needs to be fetched through php. This data should then be saved to a javascript variable by in the .php file echoing the value:
$json = json_encode($requirements);
echo "<script>
var myvar = '<?php echo $json; ?>';
</script>";
Uncaught SyntaxError: Unexpected identifier
var myvar = '<?php echo {"data":{"data":{"1":{"description":"Don' t}}}}; ?>';
You need to escape '
chars then, for example by using backslash \
:
{"data":{"data":{"1":{"description":"Don\'t}}}}
Or as you are using php you can use addslashes
function