使用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);
        }
    });

You can pass it like

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

and in php

<?php
  $members = $_GET['members_data'];
  $nonMembers = $_GET['nonMembers_data'];
?>