Home > Jquery, PHP, Programming > Embed php into Javascript

Embed php into Javascript

In javascript you cannot read variables from a server instanly however if you embed your php code you may pass variables into javascript code.

So php can pass its variables when page loads. Here is an example using jquery

<?php $variable = 'Here is value'; ?>
<script type= "text/javascript">
$(document).ready(function(){
var button = <?php echo $variable; ?> ;
});
</script>

Keep Coding

VN:F [1.9.11_1134]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.11_1134]
Rating: 0 (from 0 votes)
Embed php into Javascript, 10.0 out of 10 based on 1 rating
  1. No comments yet.
  1. No trackbacks yet.