1

Hello I am trying to pass a php variable to a javascript file like this:

 var base = "<?php echo $_SESSION['idata'];  ?>";

But when consoling I get this error:

SyntaxError: "" string literal contains an unescaped line break

Any advice could help, thanks.

2
  • 1
    var base = "<?php session_start(); echo $_SESSION['idata']; ?>"; Commented Apr 22, 2020 at 1:20
  • Worked perfectly, Thanks! Commented Apr 22, 2020 at 1:21

1 Answer 1

2

You should initialize session

var base = "<?php session_start(); echo $_SESSION['idata'];  ?>";
Sign up to request clarification or add additional context in comments.

5 Comments

This is working perfectly locally but in production base is being set to: <?php session_start(); echo $_SESSION['idata']; ?> any ideas please?
just for testing creates a new file test.php with just one line var base = "<?php session_start(); echo $_SESSION['idata']; ?>";
what is your response ?
in my computer I have: var base = "teste ";
because in my case I previously adjusted $_SESSION['idata'] = 'test'

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.