user1424074
user1424074

Reputation: 147

I can't seem to add to the array generated by serializeArray

Here's the code.

        var postData={};
    event.stopPropagation();
    postData.action='preview';
    postData.data=$("form#gaarrl").serializeArray();
    var n=[];
    n['name']='media';
    n['value']=imgName;
    postData.data.push(n);       
    console.dir(postData);
    $.post("database.php",{postData },

The console.dir command shows the media:imgName as a part of the postData.data as expected but the database.php $_REQUEST only shows the elements from the serializeArray step.

What is happening?

Thanks, Jim.

Upvotes: 0

Views: 36

Answers (1)

Robert Clarke
Robert Clarke

Reputation: 485

Try changing var n = []; to var n = {};.

This fixed it for me.

This is because normal Javascript arrays do not allow keys, just numerical indexes. {} is shorthand for new Object(), and allows you to give it multiple named attributes.

Upvotes: 1

Related Questions