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

The Archive Base Latest Questions

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

I can successfully post an array to PHP using Ajax Post but I want

  • 0

I can successfully post an array to PHP using Ajax Post but I want to extend this functionality to post an array of objects instead an array of values..im struggling to find clear examples of how to do this.

Here is how I am posting the array of values from the jQuery/Javascript client script:

var placesfortrip = {};
placesfortrip["place"+counter] = inputVal;

//note counter is an int that gets incremented for each value
//inputVal is a string with the new value to be added 

 var inputVal = jQuery("#edit-location").val();  
          jQuery.ajax({
            url: "/createtrips/updateitin",
            type: 'POST',
            data: placesfortrip,
            dataType: 'json'
            });

Then at the PHP side I read the data like this:

 $citynames = array();

    foreach ($_POST as $key=>$value) {

    $citynames[$key]= $value;

    }

How can I modify the above to post an array of objects instead of values?
Im particularly confused as to how to read the array of objects from the PHP side.

  • 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-27T19:53:51+00:00Added an answer on May 27, 2026 at 7:53 pm

    You can try this code to send your data to php file

     var status  = document.getElementsByName("status")[0];
        var jsonObj = []; //declare array
    
        for (var i = 0; i < status.options.length; i++) {
            jsonObj.push({id: status.options[i].text, optionValue: status.options[i].value});
        }
    

    then replace this line

    data: placesfortrip,
    

    with

    data: jsonObj,
    

    for other help you can also help this one

    Most of the popular JavaScript frameworks have JSON utility functions included. For instance, jQuery has a function that directly calls a url and loads the JSON result as an object : http://docs.jquery.com/Getjson

    However, you can get an open-source JSON parser and stringifier from the json website :

    https://github.com/douglascrockford/JSON-js/blob/master/json2.js

    Then, simply include the code and use the JSON.stringify() method on your array.

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

Sidebar

Related Questions

i have an iphone 3g and can successfully send text messages using the PHP
I have an HBITMAP containing alpha channel data. I can successfully render this using
I've got the basic idea covered (I think), but can't seem to successfully post
I'd like to access a PHP array using JavaScript after a successful POST. PHP
Symptom: Some users cannot successfully POST, most can successfully POST. When the error occurs,
I can successfully connect to MySQL from a DOS prompt, but when I try
I can successfully include main jquery files in /Scripts, but if my custom test.js
I am using php/ajax to submit a form without page refresh. Here are my
I am using the following PHP code to post to my page wall. it
I'm trying to post to WordPress using curl via PHP - I'm posting using

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.