Hi i need a help to pass php variable into a javascript, here is my javascript <script> $(document).ready(function() { $("#loader").load("content.php?uname=xxx"); var refreshId = setInterval(function() { $("#loader").load("content.php?uname=xxx"); }, 5000); }); </script> i want to change xxx with php variable like <script> $(document).ready(function() { $("#loader").load("content.php?uname=$name"); var refreshId = setInterval(function() { $("#loader").load("content.php?uname=$name"); }, 5000); }); </script> anyway to do like above? Thanks
So why you can't write smth like this: <?php $name = 'whatever'; print <<<HERE <script> $(document).ready(function() { $("#loader").load("content.php?uname=$name"); var refreshId = setInterval(function() { $("#loader").load("content.php?uname=$name"); }, 5000); }); </script> HERE; ?> PHP:
I am glad that you are happy with the solution you have got. There is one easier way. <script> $(document).ready(function() { $("#loader").load("content.php?uname=<?=$name?>"); var refreshId = setInterval(function() { $("#loader").load("content.php?uname=<?=$name?>"); }, 5000); }); </script> PHP: