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

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor