Home >php教程 >php手册 >PHP生成数组再传给js的方法,php生成数组js

PHP生成数组再传给js的方法,php生成数组js

WBOY
WBOYOriginal
2016-06-13 09:27:29887browse

PHP生成数组再传给js的方法,php生成数组js

<script type="text/javascript">
  var slist = '<&#63;php echo urlencode(json_encode($data['arr']));&#63;>';
  var list = eval(decodeURIComponent(slist));
  drawGpsMap(list);
</script>

怎将php数组的值传递给javascript数组?

不能直接传递,但是可以用js的ajax在页面加载的时候动态调用php数组值
或者把用php处理的数组值当字符串先赋值给html hidden控件,然后用js代码调用hidden的value
另外我觉得,如果你的这个数据不是经常改变的话,最好是用php生成一个.js文件,这个文件就定义这个数组,然后file一下,比较好
 

PHP数组中的值怎传给JS

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn