I have a php page home.php and in this I have a php variable $disableCreate = 'true';
. Please see the below code.
<?php
ob_start();
include_once("app_header.php");
$disableVar = 'true';
//below code to show the home page template
$htmlrenderObj = Htmlrender::getObj();
$template_path = $htmlrenderObj->app_home_template_path."app_home.html";
$template = $htmlrenderObj->return_file_content($template_path);
ob_end_flush();
include_once("app_footer.php");
?>
Now in the java script section I'm trying to access that variable and assign it to java script variable.
<script>
var xmlHttp = getAjaxObj();
var myJsVar = "<?php echo $disableVar; ?>";
var myJsVar2 = "<?php echo json_encode($disableVar); ?>";
var myJsVar3 = "<?=$disableVar?>";
var myJsVar4 = "$disableVar";
console.log("$$$$$$$$ myJsVar is:"+myJsVar);
console.log("$$$$$$$$ myJsVar is:"+myJsVar2);
console.log("$$$$$$$$ myJsVar is:"+myJsVar3);
console.log("$$$$$$$$ myJsVar is:"+myJsVar4);
</script>
I tried different ways to initialize my java script variable with php variable. But not get the desired output. Please see the below screenshot for reference.
Please help me.