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
491 views
in Technique[技术] by (71.8m points)

javascript - jquery serialize and multi select dropdown

I have been using the jquery serialize() function to serialize the values of a form and submit it via ajax

like for e.g. if the form name and id is factoryUsers

var data=$("#factoryUsers").serialize();

Now this works fine for forms that have text fields, text areas, simple drop downs etc. But when I have a multiple dropdown , things go awry for e.g. if I have a dropdown of the type

<select size="5" id="factoryUsers" name="factoryUsers" multiple="multiple">

the serialize doesn't work correctly anymore. so if I select 3 users I get a query string like

factoryUsers=5&factoryUsers=23&factoryUsers=11

changing the select to array type doesn't help either factoryUsers[]

Any idea or help how to get this working correctly would be great.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Try changing the name of the select to factoryUsers[]. That way you can loop through it in your backend.


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

...