McGreeb McGreeb - 5 months ago 16
Javascript Question

jQuery Post not posting multidimentional array data

I have a variable amount of tabs with custom forms on them I am trying to post the data from.

my solution was to make an array containing another array for each tab. then post that multidimensional array to my controller.

var $alltabdata = [];
$("#customtabs-holder").children().each(function() {
$tablename = $(this).attr('id');
$thistabdata = [];

$inputs = $(this).find("input");
$.each($inputs, function( index, value ) {
$thistabdata[$(this).attr("name")] = $(this).val();

$selects = $(this).find("select");
$.each($selects, function( index, value ) {
$thistabdata[$(this).attr("name")] = $(this).val();
$alltabdata[$tablename] = $thistabdata;

posting = PostTabData($client_id, $alltabdata);

posting.done(function( data ) {
}); {
alert( "Failed to post tab info" );

function PostTabData($client_id, $tabdata) {
return $.post("/CustomTables/Contents/Save",
client_id: $client_id,
alltabdata: $tabdata,

the console.log before the post displays the correct info, But the tab data doesn't end up in my controller and when i check chromes developer tools under the network option it shows the sent data as only consisting of the client_id field


Change your variables to objects:

from [] to {}

In javascript exist only Array with numeric keys. Associative Arrays not exists in javascript.

Check this snippet to fill the difference:

var arr=[];
arr["name"]="Example name";

console.log("Here array log:");

var obj={};
obj["name"]="Example name";

console.log("Here object log:");