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

Suffii
  • 5,694
  • 15
  • 55
  • 92

3 Answers3

0

try this

    <script>
        var data = "<?php echo $data; ?>";
      ...
Axel Amthor
  • 10,980
  • 1
  • 25
  • 44
0

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

Farshad
  • 1,465
  • 1
  • 9
  • 12
-1

use

<?php echo $data; ?>