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

  • SEARCH
  • Home
  • 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 9230791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:54:26+00:00 2026-06-18T05:54:26+00:00

I need to submit an html form via .ajax with jQuery. When I submit

  • 0

I need to submit an html form via .ajax with jQuery. When I submit it normally, not via ajax, everything works great. It is in switching to ajax that I encounter problems.

The form has changing number of inputs. (One each for each user in a particular group, groups can have a differing number of users). So I name the inputs like so:

<input type="hidden" name="<?php echo 'sampleA['. $i .']'; ?>" value="sampleValue" />

Where $i is a counter so the inputs are sampleA[‘1’] and sampleA[‘2’] and so on.

I have another input for each user that is done the same way, which we can call sample2[‘1’] and so forth.

So with php I just get these 2 arrays and run through them with a similar counter and insert them to my db as need. This all works well. But I need to make it ajax.

How do I pass those two arrays via jQuery’s .ajax function to a php script, and then how do I handle it in php?

I’ve tried using .serialize on my form, but that serializes both inputs on all the users into one array and I have been unable to de-serialzie that correctly on the php side of things.

The following doesn’t work, but I will include it here to show you what I’ve been doing:

function updateOnCourt() {             
    var thearray = $('#sub-form').serialize();
    $.ajax({
      url: 'sub-update.php',
      method: 'POST',
      data: thearray,
      success: function() {
        alert('Success: '+thearray);
      }
    });
  }

and then in my PHP script:

<?php 
$size = count($_POST['thearray']);
$finally = json_decode($_POST['thearray'], true);

// start a loop in order to update each record
$i = 1;

while ($i < ($size+1)) {


// define each variable
$pid = $finally[$i];
$playing = $finally[$i];


$query = "UPDATE players SET 
    on_court = '{$playing}'
WHERE id = {$pid}";

mysql_query($query, $connection);

$i = $i + 1;

} ?>    

What am I doing wrong?

  • 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-18T05:54:27+00:00Added an answer on June 18, 2026 at 5:54 am

    thearray is only a variable name in javascript, so there is no $_POST['thearray'] and the data is not sent as JSON so no need to use json_decode

    You want to access the name attributes in the form controls:

    Try looking at $_POST['sampleA'].

    Look at docs for serialize() will see that it sends the data in same format as if form was submitted without AJAX

    API Reference: http://api.jquery.com/serialize/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to submit a form in a Colorbox modal via ajax (that
I need to submit a form which triggers a workflow that goes through different
I need to submit data from a form to an SQL2005 database via a
Need the three Options to be hyperlinks that submit the choice form. When submitted,
I need to grab the HTML of the current page and submit it via
I am trying to create a form that posts data via jQuery and populates
I need to upload multiple images via form. I thought that I will do
I need to submit a hash of attributes directly from the form tag. Is
I have a problem posting file via ajax jQuery function. I have something like
I'm using the jquery form plugin ( http://malsup.com/jquery/form/ ) to upload a file via

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.