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);
        }
    });
1

1 Answer 1

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'];
?>
Sign up to request clarification or add additional context in comments.

2 Comments

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 glad you've find the solution .. Have a great day :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.