0

I have a config.php file in which I defined a variable SITE(define('SITE',"siteroot") and I have a .js file which included jquery functions. In that file, I have a variable site_root.

Is it possible I can make site_root=<?=SITE?>

I change the .js file to php file and used this code header("Content-type: application/javascript"); to defined the type of the file and include the config file. However, site_root=<?=SITE? return "".

2 Answers 2

2

I'm not sure if you have a typo in the question or in the actual code, but

define('SITE',"siteroot");

and

var site_root = "<?= SITE ?>";
//              ^           ^ quotes matter

should work fine.

Sign up to request clarification or add additional context in comments.

Comments

1

Declare PHP Variable

<?php 
$variable = "abc";
?>

<script>
$("document").ready(function(){
var test = "<?php echo  $variable; ?>";
alert(test);
});
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.