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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:58:13+00:00 2026-06-06T23:58:13+00:00

Hi I need to build data in a JSON object and send through a

  • 0

Hi I need to build data in a JSON object and send through a ajax post, as a String.

I need to send something in the following format:

{
 "myRequest": {
     "myRequestType": "updateStatus",
     "fields": [
         {
             "item1": "data1",
             "item2": "data2",
             "item3": "data3",
             "formUpdateField": "data4"
         }
     ]
 }
}

I have a form table, which has a checkbox to select record(s) to send the update for. basically the send is to update a status of a record.

Based on the above, I have access to item1, item2 and item3 data – this is non form data. I need to add this to a JSON object. I think I can just about do this. But my problem is, I need to then add the data that I have from the form too, to this JSON Object.

I am able to get the data out of the form, but how to I add this to the JSON object I am building up?

The other issue is that, you can select multiple records from the form table

Any ideas how I can do this using JSON/jQuery etc?

  • 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-06T23:58:14+00:00Added an answer on June 6, 2026 at 11:58 pm

    Build your object as an object, then stringify it later. It’s far harder to string-handle a JSON string together yourself than it is to stringify later.

    If you’re happy to support modern browsers only, you can take advantage of the native JSON.stringify() method that arrived in ECMA5. If not, there are plenty of third-party scripts that do the same thing.

    Try this:

    HTML (simple form)

    <form id='myForm'>
        <input type='text' name='foo' />
        <input type='text' name='bar' />
        <input type='checkbox' name='foobar' />
        <input type='submit' value='go'>
    </form>
    

    JS

    $(function() {
    
        //initialise object
        $('#myForm').on('submit', function() {
            var data = {
                myRequest: {
                    myRequestType: 'updateStatus',
                    fields: [{
                        item1: 'data1',
                        item2: 'data2',
                        item3: 'data3',
                        formUpdatedField: 'date4'
                    }]
                }
            };
    
                //iterate over form fields and add each one in to our data
            $(this).find('input:not([type=submit]), select, textarea').each(function() {
                data.myRequest.fields[0][$(this).attr('name')] = $(this).val();
            });
    
                //do the request
            $.ajax({url: 'some/url.php', method: 'post', data: JSON.stringify(data)}).done(function() {
                //on success...
            });
            return false;
        });
    });
    

    That will iteratively append the fields and their values to your object, then stringify it when sending it as part of the AJAX request.

    Finally, couldn’t your fields definition be just an object, rather than an array whose existence is purely to house the inner object? Seems needless, but perhaps there’s more to your data structure than you’ve shown.

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

Sidebar

Related Questions

I have a need to build the data string dynamically. This is not working,
I have the following: @rooms = current_user.rooms Then I need to build a JSON
I need to build an application that accepts user input data (such as name,
I am using $.post to send a json structure built out of user input:
I know barely nothing about JSON and I need to send a request to
Phil Haack has an excellent blog post on how to use JSON, data binding,
This I'm trying for transfer my current Apache/Modperl site to Starman, and need build
I need to build app with user messages (dialogs). I've solved this problem by
I need to build a feature like most of the banks use. Where.. if
I need to build a push system in django, basicly its function is to

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.