0

I have a php varaiable that I need to pass into a link in a javascript function

//In the config
<?php
    define('THE_VAR', 'test');
?>


//On the page
<?php
    $the_var = THE_VAR;
?>

<script>
    (function()){
        link = "test.site"+<?php echo json_encode($the_var); ?>+"/testing.js"
    })();
</script>

I need the link in the javascript function to read.

test.site/test/testing.js

2 Answers 2

2

Instead of: link = "test.site"+<?php echo json_encode($the_var); ?>+"/testing.js"

Use: link = "test.site/<?= $the_var; ?>/testing.js";

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

2 Comments

that just outputs "test.site/'+"test"+'/testing.js";
True, I made a mistake! Try it now, I edited my post.
-1

Use Ajax for passing the data from php into the javascript.

http://www.w3schools.com/ajax/ajax_php.asp

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.