pull JSON data from a text file and put it in an array in javascript -
i have text file named "vars.txt" holds array. how can pull information , put in javascript array? right have
<script type="text/javascript"> function test() { var testvar = <?php file_get_contents('vars.txt') ?>; alert ("success"); alert (testvar); }; </script> and not working. there better way pull data array?
<script type="text/javascript"> function test() { var testvar = <?php echo file_get_contents('vars.txt') ?>; alert ("success"); alert (testvar); }; </script> you forgot echo data, without nothing rendered javascript function.
to debug situations this, view source of rendered webpage, , see what's printed.
Comments
Post a Comment