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

js传递二维数组给php

WBOY
Release: 2016-06-23 13:32:55
Original
1364 people have browsed it

以前使用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>
Copy after login


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

多谢两位版主哈!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template