tags:

views:

31

answers:

3

Hi,

I need to serialize my form data and send it via ajax I have used serializeArray() which gives me the approriate postdata. The code is as follows :

var fields = $('#myform :input').serializeArray();
                jQuery.each(fields, function(i, field)
                {

                     values[field.name]  = field.value

                });

I want to pass values[field.id] = field.value I want to use serializeArray() only becoz it uses the standard W3C rules for successful controls to determine which elements it should include .

A: 

I think that a better approach is to use this jQuery Form Plugin:

http://jquery.malsup.com/form/

I have used successfully in many projects.

Impiastro
A: 

I think this is a repost:

        var values = {};
        $("#myform :input").each(function(i, field) {
              values[field.id] = field.value;

        });

        JSON.stringify(values));
naikus
A: 

There’s also .serialize().

Mathias Bynens