[Solved] Acessing php variable using jquery [closed]


If the side is being processed through PHP (on the server) you can just use an echo

<pre>
<script>
    $(document).ready(function(){       
        var timeLeft = <?php echo 12796; ?>;
        console.log(timeLeft);  
    });
</script>

After PHP has processed the page it is just regular javascript as if you wrote it manually.

You can also imagine the following example:

<html>
  <head>
    <script type="text/javascript">
      alert('<?php echo 'hello js' ?>');
    </script>
  </head>
  <body>
  </body>
</html>

Save it as hello.php inside of your web servers document root and call it in browser.

5

solved Acessing php variable using jquery [closed]