开发者

serializing a form jquery

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

       开发者_StackOverflow中文版         });

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 .


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.


I think this is a repost:

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

        });

        JSON.stringify(values));


There’s also .serialize().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜