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 5945611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:42:22+00:00 2026-05-22T16:42:22+00:00

I am using AJAX to put some data in my database. I am using

  • 0

I am using AJAX to put some data in my database. I am using JSON to submit the data to a PHP page. I am using a POST request. Can you set one of the POST variables as an array? Below I have the full AJAX request, but here is the part where I am setting two parts of the data as arrays:

"content[]" : testContentArray,
"content_attr[]" : testContentAttributes,

Below is my full AJAX (using jQuery):

$.ajax({
                type: "POST",
                url: "../includes/create_test_main.ajax.php",
                data:   {"tags" : $('#testTags').val(),
                                         "title" : $('#testTitle').val(),
                                         "subject" : $('#testSubject').val(),
                                         "description" : $('#testDescription').val(),
                                         "content[]" : testContentArray,
                                         "content_attr[]" : testContentAttributes,
                                         "user_id" : user_id},
                success: 

                                     function(testId) {//redirect Page
                                        window.location.href = "http://localhost/nvr_forget/public_html/test/" + testId + "/";
                                     }
            });
        };

If that is the way to do it, how would I handle it on the PHP side? do I handle the $_POST variable as a normal array?

  • 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-05-22T16:42:23+00:00Added an answer on May 22, 2026 at 4:42 pm

    When you pass an array within a data object to $.ajax, it is parsed out into name[]=value format. This is done using $.param, so I’ll illustrate using that:

    jQuery.param({'foo': [1, 2, 5]})
    // "foo%5B%5D=1&foo%5B%5D=2&foo%5B%5D=5"
    

    %5B and %5D are uri-encoded square brackets. This is a common way of sending multiple values for the same key to a server. PHP parses it into an array, so in this case:

    var_export($_POST['foo']);
    // array ('1', '2', '5')
    

    So in your code, $_POST['content'] and $_POST['content_attr'] should both be arrays. The square brackets that you’ve used are unnecessary, but won’t break anything.

    See the PHP manual on the subject.

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

Sidebar

Related Questions

I am making an ajax request using JQuery that looks like this: var data
I'm using jQuery.ajax() to make a PUT request to a REST web service, but
I have a button that grabs some data from the server using ajax, and
In a ajax-driven site I have added some default data using the ajaxSetup, ala
I am using this pseudocode to retrieve some json files and put their content
I'm running Sitecore 6.4 and trying to get some data using ajax and webmethod
I've put together some jQuery AJAX code using some tutorials I found on the
I need to get a range of pages using AJAX and put them into
I'm using PUT and DELETE more and more w/ my ajax work and wanted
I am using the jQuery $.ajax() function. I have put this into a parent

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.