how to send a variable from PHP to jQuery -
the idea is:
<script type="text/javascript"> var supervar = 'u can reach me anywhere on page'; </script> [...some php , html...] <script type="text/javascript"> $('#output').html(supervar); </script>
so basicly need because use php includes , need send exact location of php file jq.
your supervar
variable in scope inside jquery, because declared above jquery script. question how assign variable php , pass on supervar
. inside .php
file, can escape php when needed within <script>
element.
for example, if want assign public path of php script, can like:
<script type="text/javascript"> var supervar = <?php echo $_server['php_self']; ?>; </script>
your server execute php script before serving following output client:
<script type="text/javascript"> var supervar = '/your-app/your-file.php'; </script>
Comments
Post a Comment