开发者

serializing a form jquery

开发者 https://www.devze.com 2023-01-10 07:46 出处:网络
I need to serialize my form data and send it via ajax I have used serializeArray() which gives me the approriate postdata.

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

精彩评论

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