AJAX Post Multiple Arrays

Matt Pierce

I have 2 input fields like so

<input type="text" name="typeDetails[games]"/>
<input type="text" name="typeDetails[art]"/>

I want to submit via AJAX, but I'm unsure how to exactly send this data. I know in my controller that I can validate the typeDetails array like typeDetails.games or typeDetails.art, but I'm unsure how to send it.

Here's what my JS looks like currently.

var data = { 'typeDetails[]' : []};

$("input[name='typeDetails[games]']").each(function() {
    data['typeDetails[games]'].push($(this).val());
}); 

$("input[name='typeDetails[art]']").each(function() {
    data['typeDetails[art]'].push($(this).val());
});

The error I'm getting is "Cannot read property 'push' of undefined".

Thanks!

Vinoth K

'typeDetails[games]' and 'typeDetails[art]' are not the keys of data.

Declare data like this

var data = { 'typeDetails[games]' : [],  'typeDetails[art]' : []};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Ajax post returns multiple arrays with objects that have multiple values

From Dev

How can i post multiple arrays with JQuery AJAX in an MVC controller?

From Dev

AJAX: how to post empty arrays?

From Dev

AJAX Post for multiple form

From Dev

Ajax post multiple data

From Dev

POST multiple AJAX data

From Dev

PHP $_POST arrays with multiple rows

From Dev

Multiple nested AJAX requests with arrays

From Dev

Post multiple value using ajax

From Dev

Post multiple value using ajax

From Dev

Post multiple jquery with ajax to python

From Dev

Ajax post with multiple query not working

From Dev

AJAX - submit multiple POST data

From Dev

multiple ajax and form post requests on multiple pages

From Dev

Convert multiple objects to json in ajax post

From Dev

ajax post request sending multiple request

From Dev

Serialize multiple CakePHP formhelper forms for ajax post

From Dev

Ajax json post to php for multiple return values

From Dev

Receiving multiple data with jQuery ajax POST

From Dev

AJAX post multiple data after file upload

From Dev

Post Data and Multiple Image using Ajax

From Dev

AJAX POST Send Multiple DIV value

From Dev

How to insert into MYSQL row from multiple $_POST arrays

From Dev

Pass multiple arrays from PHP through jQuery AJAX to Javascript

From Dev

Passing multiple arrays from PHP to AJAX and JQuery Autocomplete with JSON

From Dev

jquery ajax post file , multiple files and text input

From Dev

AJAX Post Multiple Data to ASP.Net MVC

From Dev

How to handle a multiple files response from a Ajax POST request?

From Dev

Add multiple meta key and value in AJAX post filter