doumengjing1500 2013-12-05 13:18
浏览 47
已采纳

使用PHP内部数组解析数组

I have array in my JS and I have to parse it to PHP:

var transfer_data = {
            cl_name : $("#free_1_1_title").val(),
            contact_name : $("#free_1_1_name").val(),
            contact_lastname : $("#free_1_1_lastname").val(),
            contact_email : $("#free_1_1_email_1").val(),
            cl_alley : $("#free_1_1_select_1").val(),
            cl_services : $("#free_1_1_select_2").val(),
            cl_tags : {
                1 : $("classified_tag_1").val(),
                2 : $("classified_tag_2").val(),
                3 : $("classified_tag_3").val(),
                4 : $("classified_tag_4").val(),
                5 : $("classified_tag_5").val()
            }
        };

and transfering:

$.ajax({
            url: "classifieds/add_new/addNewCl_1_1",
            type: 'POST',
            dataType: 'json',
            data: transfer_data, 
            success: function(data) { 
                  console.log(data.response);
            },
            error: function (e) {
                console.log(e.message);
            }
        });

and I want to receive it like that:

Array
(
    [cl_name] => value
    [contact_name] => value
    [contact_lastname] => value
    [contact_email] => value
    [cl_alley] => value
    [cl_services] => value
    [cl_tags] => array(1 => value, 2 => value...)
)

so how I should be supposed to do it? I tried to print receiving data with print_r($_POST);

and I got only

Array
(
    [cl_name] => value
    [contact_name] => value
    [contact_lastname] => value
    [contact_email] => value
    [cl_alley] => value
    [cl_services] => value
)

I'm missing my cl_tags with values

  • 写回答

2条回答 默认 最新

  • dsms21398 2013-12-05 13:25
    关注

    You need to change variable name in js

    So working code are follow:

    var data = {
        q:1, 
        'w[]': [1,3,4,5,7],
        'e[t1]': 1,
        'e[t2]': 2,
        'e[t3]': [1,2,3,4,5]
    }
    $.ajax({url:'/', type: 'POST', data: data});
    

    In chrome debug we see follows:

    q:1
    w[]:1
    w[]:3
    w[]:4
    w[]:5
    w[]:7
    e[t1]:1
    e[t2]:2
    e[t3][]:1
    e[t3][]:2
    e[t3][]:3
    e[t3][]:4
    e[t3][]:5
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄