0

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);
        }
    });
Chief
  • 127
  • 9

1 Answers1

2

You can pass it like

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

and in php

<?php
  $members = $_GET['members_data'];
  $nonMembers = $_GET['nonMembers_data'];
?>
Mohamed-Yousef
  • 23,946
  • 3
  • 19
  • 28
  • that seemed to do the trick, nice and easy thank you! It was complaining when I did a print_r on both but that's because one didn't have data as I call that ajax each time a field is changed... so I just had to modify the PHP so it tested first. if( isset($_GET['members_data']) ) {} – Chief May 27 '17 at 23:56
  • @Chief glad you've find the solution .. Have a great day :-) – Mohamed-Yousef May 27 '17 at 23:59