dsy19890123 2017-05-27 21:47
浏览 85
已采纳

使用AJAX将两个不同的jQuery数组传递给php(普通数组和多维数据)

I'm using ajax to do calculations as people fill out a form. I'm trying to figure out how to pass 2 different types of arrays with AJAX and do stuff with them in PHP. First array is just ID's, 2nd array is multidimensional.

"members" array is from jQuery Chosen field which creates arrays of all the member ID's such as ["1", "1116210"].

var members = [];
members.push(id);  // loop through and push ID to "members" array

This works when i send it like

data: { "data": members }

Second array I don't know how to pass too, is multidimensional from 4 different input boxes so it looks something like this in jQuery.

nonMembers[0]['name']
nonMembers[0]['email']
nonMembers[0]['rating']
nonMembers[0]['gender']

Here's my ajax call to a PHP file

$.ajax({
        url:url,
        data: { "data": members },
        beforeSend: function() {
            $('.MembersPostback').html('<div class="loading"><img src="/images/loading.gif" /></div>');
        },
        success: function(response){ 
            $('.MembersPostback').html(response);    
        },
        error: function(xhr, status, error) {
            alert(xhr.responseText);
        }
    });
  • 写回答

1条回答 默认 最新

  • dsdukbc60905239 2017-05-27 21:49
    关注

    You can pass it like

    data: { members_data: members , nonMembers_data : nonMembers},
    

    and in php

    <?php
      $members = $_GET['members_data'];
      $nonMembers = $_GET['nonMembers_data'];
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)