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

js传接二维数组给php

WBOY
WBOYOriginal
2016-06-13 12:21:351251browse

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



------解决思路----------------------

------解决思路----------------------
例子:

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


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

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