Search code examples
javascriptjqueryjquery-1.9jquery-data

How to add more data into an exisitng data using jquery?


How can I add more data into an exisitng data using jquery - or just plain javascript?

fd = {
    name : file_data.name,
    size : file_data.size
};

// And others.
$("form").find('input[type=hidden]').each(function(){
    $(fd).data(this.name, this.value);
});

I get this strange result,

Array
(
    [name] => Dangerous Man.mp3
    [size] => 11912748
    [jQuery1910560199169432603] => Array
        (
            [toJSON] => undefined
            [data] => Array
                (
                    [article_id] => 
                    [category_id] => 15
                    [user_id] => 1
                    [max_upload_filesize] => 3
                    [method] => upload
                    [required[category_id] => Category ID
                )

        )

)

But I am after this result,

Array
(
    [name] => Dangerous Man.mp3
    [size] => 11912748
    [article_id] => 1
    [category_id] => 15
    [user_id] => 1
    [max_upload_filesize] => 3
    [method] => upload
    [required[category_id] => Category ID

)

any ideas?


Solution

  • Just add property to object

    $("form").find('input[type=hidden]').each(function(){
        fd[this.name] = this.value;
    });