Note that there are some explanatory texts on larger screens.

plurals
  1. POajax post multiple input groups
    text
    copied!<p>I have a form with 4 groups of checkboxes used to refine search results. I want to be able to post an array for each checkbox group containing the id's of the checkboxes currently ticked. </p> <pre><code> $.ajax({ url: "/stay_in_belfast/accommodation", type: "POST", data: { subcategory_ids:$(":checkbox[name^='subcategory_ids[']").serialize(), rating_ids:$(":checkbox[name^='rating_ids[']").serialize(), location_ids:$(":checkbox[name^='location_ids[']").serialize(), facility_ids:$(":checkbox[name^='facility_ids[']").serialize() }, success: function( data ) { } }); </code></pre> <p>When I post this though my array contains four variables as expected, except the data looks like:</p> <pre><code>subcategory_ids%5B%5D=22&amp;subcategory_ids%5B%5D=23&amp;subcategory_ids%5B%5D=24&amp;subcategory_ids%5B%5D=26&amp;subcategory_ids%5B%5D=27&amp;subcategory_ids%5B%5D=28 </code></pre> <p>If I use serializeArray each of the four post variables contain a name paired array with the input name and the value. However the input name is always going to be the group name of the input for that group and therefore is of no real use to me. If I try this just sending one group through such as </p> <pre><code>$.ajax({ url: "/stay_in_belfast/accommodation", type: "POST", data: $(":checkbox[name^='subcategory_ids[']").serialize(), success: function( data ) { } }); </code></pre> <p>It shows up the the post as an array of the id's. I can't figure out why it's different depending if I post through a single grouping or post through four groupings. </p> <p>Basically all I want in my post is 4 arrays identified by their input group with each array contains a list of id's. Am sure this is possible but I am just missing it.</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload