开发者

Looking for a jquery plugin to serialize a form to an object [closed]

开发者 https://www.devze.com 2022-12-30 21:16 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions see开发者_C百科king recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 7 years ago.

Improve this question

I'm looking for a jQuery function or plugin that serializes form inputs to an object using the naming convention for deep-serialization supported by param() in jQuery 1.4:

<form>
  <input name="a[b]" value="1"/>
  <input name="a[c]" value="2"/>
  <input name="d[]" value="3"/>
  <input name="d[]" value="4"/>
  <input name="d[2][e]" value="5"/>
</form>

$('form').serializeObject(); // { a: { b:"1",c:"2" }, d: ["3","4",{ e:"5" }] }

Prototype's Form.serialize method can do exactly this. What's the jQuery equivalent? I found this plugin but it doesn't follow this naming convention.


Since there didn't seem to be any existing libraries that accomplished what I was seeking, I mashed up bits from a couple of existing libraries that did similar things:

  • The jQuery.deparam function from jQuery BBQ
  • The jQuery.serializeObject function mentioned in the question.

Both are by Ben Alman. Thanks, Ben!

The result: http://gist.github.com/405448


try using jquery form plugin. I haven't tested it, but I think it will fix your problem

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


You do not need pluging.

$('form').submit(function() { alert($(this).serializeArray()); return false; });

look at http://api.jquery.com/serializeArray/


Maybe late, but there's a jQuery plugin thad does what you need.

http://v3.javascriptmvc.com/index.html#&who=jQuery.fn.formParams

0

精彩评论

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