php - Error with strings in JavaScript -
i have rare problem variables between php , javascript.
this example:
<?php $test = "123"; ?> $(document).ready(function(){ alert('.$test.'); });
works fine, if put $test = "hello"; doesn't works fine. works in js when put numbers.
the php variable server side variable. javascript accessing variable on client. in order javascript need like:
<?php $test = "123"; ?> $(document).ready(function(){ alert('<?php echo($test); ?>'); });
that should it!
alternate approach
the alternative set variable in javascript have value on client. looks like:
<?php $test = "123"; ?> var $test = <?php echo($test); ?>; $(document).ready(function(){ alert('.$test.'); });
the nice part can use "$test" anywhere need without worrying client versus server.
Comments
Post a Comment