Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

jQuery serialize / serializeArray from an element that is not a form

I haven't found a concrete answer as to whether this is possible, but it seems like it should be...

I would like to serialize all the input elements contained in a div. I can't use a form, because it would be nested within another form. I would then get the values and post them via ajax.

Here is the jsFiddle example I am playing with:

http://jsfiddle.net/9uyz5/

If I change the root to a it works as expected.

Thanks for your help.

I've modified the jsfiddle from this other question:

https://stackoverflow.com/a/1186309/25020

question from:https://stackoverflow.com/questions/9589126/jquery-serialize-serializearray-from-an-element-that-is-not-a-form

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you need to serialize all the inputs inside your container, not the actual container itself. so:

$('div :input').serialize()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...