jQuery的序列化和多选择下拉列表

jQuery的序列化和多选择下拉列表

本文介绍了jQuery的序列化和多选择下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用jquery serialize()函数来序列化表单的值,并通过ajax提交



。如果表单名称和ID是 factoryUsers



var data = $(#factoryUsers)。serialize ;



现在这适用于具有文本字段,文本区域,简单的下拉列表等的表单。
但是当我多重下拉菜单,例如,出现错误
如果我有一个类型的下拉菜单

< select size =5id =factoryUsersname =factoryUsersmultiple =多个>



serialize无法正常工作。
,所以如果我选择3个用户,我会得到一个查询字符串,例如:
$ b

factoryUsers = 5& factoryUsers = 23& factoryUsers = 11



将select改为数组类型不会帮助 factoryUsers []



任何想法或帮助如何正确工作都会很棒。

>上面描述的字符串输出是通过HTTP为具有相同名称的表单提交多个值的正确方法,所以jQuery工作正常。这取决于你在服务器端如何处理它,然后依赖于你正在使用的语言。



如果你使用的是PHP,可能会有所帮助:



你能否告诉我们你使用什么语言?


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 awryfor 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.

解决方案

The string output you've described above is the correct way of submitting multiple values for forms with the same name over HTTP, so jQuery is working correctly. It's up to you to handle how this is processed on the server-side, which is then dependent on what language you are using.

If you're using PHP, this may help: http://bytes.com/topic/php/answers/12267-how-php-_post-gets-multiple-values-html-form

Can you tell us what language you're using?

这篇关于jQuery的序列化和多选择下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:11