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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:46:14+00:00 2026-05-22T01:46:14+00:00

I need to POST a JSON String containing a List of 1 or more

  • 0

I need to POST a JSON String containing a List of 1 or more values from a multiple select form. In the JQuery solution I came up with, I am getting all of the values selected in the list, but they are being returned as individual parameters.

$(document).ready(function() {
  $("#fooForm").submit(function(event) {
    event.preventDefault();         
    var $form = $(this),
    loc = $form.find('input[name="location"]').val(),
    url = $form.attr('action'),
    keys = $('#people :selected').map(function(){return $(this).val();}).get();
    $.post(url, {people:keys, location:loc},
        function(data) {
          $("#result").html(data);
        }
    );
  });
});

<form id="fooForm" method="" action="/api/people/location">
  <input type="hidden" name="location" value="{{location}}" />
  <select id="people" multiple size=4>
   <option value="{{a.key}}">{{a.name}}</option>
   <option value="{{b.key}}">{{b.name}}</option>
   <option value="{{c.key}}">{{c.name}}</option>
   <option value="{{d.key}}">{{d.name}}</option>
  </select> 
  <input type="submit" value="Submit" />    
</form>

This produces the following parameters if say, three people are selected:

location     91.001,-11.23
people[] agxzdXBlcmxhcnAtc2ty_foo
people[] agxzdXBlcmxhcnAtc2ty_spam
people[] agxzdXBlcmxhcnAtc2ty_eggs

I would expect there to be a single people parameter containing the three key values.


UPDATE
Here’s the most elegant solution I came up with:

$(document).ready(function() {
  $("#fooForm").submit(function(event) {
    event.preventDefault();         
var dataToBeSent = $("#fooFoorm").serialize();
var url = $("#fooForm").attr('action');
    $.post(url, dataToBeSent,
        function(data) {
          $("#result").html(data);
        }, "json"
    );
  });
});

<form id="fooForm" method="" action="/api/people/location">
  <input type="hidden" name="location" value="{{location}}" />
  <select name="people" multiple size=4>
   <option value="{{a.key}}">{{a.name}}</option>
   <option value="{{b.key}}">{{b.name}}</option>
   <option value="{{c.key}}">{{c.name}}</option>
   <option value="{{d.key}}">{{d.name}}</option>
  </select> 
  <input type="submit" value="Submit" />    
</form>
  • 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-22T01:46:14+00:00Added an answer on May 22, 2026 at 1:46 am

    The standard way to send a list in parameters is to use one param for each item in the list (and then it’s convention to name that param “whatever[]” to indicate that it’s a list).

    Also, you really should be using a name for your SELECT, not an id; you’re not supposed to have multiple elements with the same ID on the page, and name is really the attribute for “naming” form data.

    An easier way to do what you’re trying to do would be to use the jQuery serialize method. This would let you do:

    keys = $("#fooForm").serialize()
    

    However, I’m pretty sure that will do the multiple parameters thing too, so if you really must have a single parameter then you are stuck doing something like:

    keys = ""
    $('#people :selected').each(function(){
        keys += $(this).val() + ",";
    });
    // Strip off the trailing comma if present
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to serialize all inputs from a form into a JSON string. With
I need to post 60 inputs. I have built up the json string and
From post: Sending a JSON array to be received as a Dictionary<string,string> , I'm
I need to post a form which includes personal details and I need to
I need to post a form on a new website which is UTF-8 encoded.
I've got a form and I need to post data to the server every
I need to do some reports that aren't strictly a listing-of-entities. More free-form query,
My POST method looks like this: @POST @Consumes({application/json}) @Path(create/) public void create(String param1, String
I have a Restlet Service that looks like this: @POST @Produces(application/json) public String processImmediately(String
I deserialized json string to List<ClassB> and now I want to cast it 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.