0

Can you please take a look at this code and let me know why I am not able to pass variable value from PHP to jQuery?

<?php
$data = "This is For Test";
?>

<!DOCTYPE html>
  <head>  </head>
  <body>
    <button id="test" type="button" class="btn btn-default">Default</button>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

    <script>
    var data = "<?php $data; ?>";
    $("#test").on("click",function(){
     alert(data);
    });
    </script>
  </body>
</html> 

Thanks

0

3 Answers 3

0

try this

    <script>
        var data = "<?php echo $data; ?>";
      ...
Sign up to request clarification or add additional context in comments.

Comments

0

You have missed echo for <?php echo $data; ?>

Comments

-1

use

<?php echo $data; ?>

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.