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

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -