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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:50:22+00:00 2026-05-27T23:50:22+00:00

I am trying to post an array of objects from jQuery/Javascript client script to

  • 0

I am trying to post an array of objects from jQuery/Javascript client script to server side PHP script.

Im still confused about the format that the object array data should be in before reaching the server.

I create an array to store the json objects

var jsonObjects = [];

I add individual json objects to the array

var jsonObj1 = {};
 jsonObj1.place = "London";
 jsonObj1.position = 1;

 jsonObjects.push(jsonObj1);

 var jsonObj2 = {};
 jsonObj2.place = "Melbourne";
 jsonObj2.position = 2;

 jsonObjects.push(jsonObj2);

..etc

I then try to post this data via ajax post (Ive tried stringifying before the post and also tried without stringifying)

e.g.

//var data = jsonObjects;
//var data = JSON.stringify(jsonObjects);

jQuery.ajax({
            url: "/drupal/menu_item",
            type: 'POST',
            data: data
            dataType: 'json'
             });

Either way on the XHR tab in Firebug it just shows a stringified version of the data
e.g.
[{“place”:”London”,”position”:”2″}, {“place”:”Melbourne”,”position”:”2″}]

rather than it looking like what the post details have looked like before with the data broken up into parameters. Unless of course PHP finding data in the stringified state will actually work (?)

I seem to be finding conflicting details as to how sending an array of json objects to PHP should be done. At the point that the ajax request is executed what state should the data be in?
a) stringified array of objects
b) array of objects
c) something else again (?)

Any help to clarify this is much appreciated 🙂

Thanks,

Rowan

  • 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-27T23:50:22+00:00Added an answer on May 27, 2026 at 11:50 pm

    Stringified data is just a textual representation of a JS object. Therefore, you can run json_decode on the stringified JS object in order to obtain PHP data structure.

    On the other hand, if your objects are simple key:value ones without much depth (multi-dimensional arrays) then they can be sent as querystring and parsed into PHP’s $_POST / $_GET / $_REQUEST

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

Sidebar

Related Questions

Hi I am trying to serialize an array of objects which are derived from
I'm trying to post some very simple data to a php file using jquery
I'm trying to pass an array from a jQuery function to my controller. The
I am trying to post an array full of checkboxes and to open it
I'm trying to POST a http request using ajax, but getting a response from
Hmm... i'm trying to use a php variable in jquery, in my edit.php :
I was trying to use jQuery UI Nested Sortable 1.2.1 from http://mjsarfatti.com/sandbox/nestedSortable where it
Im trying to use this jQuery script and this is confusing me: function CallService()
I am trying to access and change a array from a different class file.
Following on from a previous post , I've found I'm totally stuck. I'm trying

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.