开发者

from php to jquery

开发者 https://www.devze.com 2023-01-11 00:56 出处:网络
i have array in php, and i need wo开发者_开发问答rk with this array in jQuery. What best way send array( or variable ) from php to jQuery?

i have array in php, and i need wo开发者_开发问答rk with this array in jQuery. What best way send array( or variable ) from php to jQuery? Thanks


json_encode() (PHP >= 5.2) is arguably the easiest way.

$array_js = json_encode($array);

echo "<script type='text/javascript'> my_array = ".$array_js."; </script>";


If you don’t have to dynamically load it, try something like this:

<script>
var the_array = <?php echo json_encode($array); ?>
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消