Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8031385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:05:13+00:00 2026-06-05T01:05:13+00:00

I’ve successfully posted a single array, but I can’t figure out how to send

  • 0

I’ve successfully posted a single array, but I can’t figure out how to send more than one array in an AJAX post. Here is my code for one array:

var a = new Array();
// fill array
var a_post = {};
a_post['array1[]'] = a;

$.ajax({
    url: "submitOrder.php",
    data: a_post,
    type: 'post',
    success: function(data) {
        alert(data);
    }
});

And in submitOrder.php I have:

$array1= $_POST['array1'];

foreach ($array1 as $a => $b)
echo "$array1[$a] <br />";

This works fine. However, when I try to add a second array b_post to the data: field, it doesn’t work. I tried data: {a_post, b_post}, and a few variations of that, but I can’t get it to work properly. While I’m at it, how would I then load submitOrder.php after posting rather than show an alert of the data?

UPDATE

Using Nicolas’ suggestion, I got this to work changing the data field to:

data: {'array1':JSON.stringify(a), 'array2':JSON.stringify(b)},

However, I also need to add the rest of the form data that has been input by the user. I can get this data with $(this).serialize() but if I try to add that to the data field, it does not work. How can I add this data to the above line?

Thanks.

SOLUTION

What ended up working the way I originally had hoped for (with Nicolas’ help):

var formData = $(this).serializeArray();
var a_string = JSON.stringify(a);
formData.push({name: 'array1', value: a_string});
var b_string = JSON.stringify(b);
formData.push({name: 'array2', value: b_string});

$.ajax({
    url: "submitOrder.php",
    data: formData,
    type: 'post',
    success: function(data) {
        alert(data);
    }
});            
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:05:14+00:00Added an answer on June 5, 2026 at 1:05 am

    The data should be encapsuled this way

    data: {'first_array':JSON.stringify(array1),'second_array':JSON.stringify(array2)}
    

    Then in PHP:

    $array1 = json_decode($_POST['first_array']);
    $array2 = json_decode($_POST['second_array']);
    

    You can add the rest of the inputs as well.

    data: {'first_array':JSON.stringify(array1),'second_array':JSON.stringify(array2),'input1':$(input[name="input1"]).val()}
    

    Just repeat with all the inputs you want to send.

    'input1':$(input[name="input1"]).val(),'input2':$(input[name="input2"]).val(),... etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.