Home >Backend Development >PHP Tutorial >js传递二维数组给php

js传递二维数组给php

WBOY
WBOYOriginal
2016-06-23 13:32:551368browse

以前使用js给php传参都是传的string类型的,今天需要用ajax传递一个二维数组给php,不知道怎么做,请教各位高手们。



回复讨论(解决方案)

例子:

    <script type="text/javascript">    $.post("server.php",{name:[[1,2],[3,4]]})      .done(function(data){        alert(data[0][1]); // 输出2      });    </script>


server.php
header('content-type:application:json;charset=utf8');echo json_encode($_POST['name']);

多谢两位版主哈!

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