donglie1898 2014-04-04 17:14
浏览 115

JavaScript / jQuery多维数组(对象)到php

I want to send a array to php with this structure:

Array[0]['name'] = ...
Array[0]['def'] = ...
Array[1]['name'] = ...
Array[1]['def'] = ...

and so on....

To do this I have a multidimensional array object like this:

var allShapes = new Array();
$('.shape_name').each(function(index){
    allShapes[index] = new Array();
    allShapes[index]['name']=$(this).val();

    allShapes[index]['def']=$(this).closest("tr").find('*[id*=shape_def_]').val();
});

I send it through a post request to php:

$.post("../some.php", {
    'shape_defs' : allShapes
}, function() {

    console.log(allShapes);

}, "json").success(function() {
   console.log("success");
});

How do I have to iterate through thos array in php? Something goes wrong there......

The Array which comes as $_POST (after json_decode) has the following content:

[{"name":"Ta","def":"somestring"},{"name":"WSCall","def":"somestring"},{"name":"manual","def":"somestring"}]

How do I iterate to get the values of the keys?

  • 写回答

2条回答 默认 最新

  • dongyou8701 2014-04-04 17:20
    关注

    Serializing your array using JSON.stringify and then parsing it in PHP using json_decode should fix your problem. Complex data structures generally don't transfer well without encoding them.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器