使用jQuery,如何模拟在$ .ajax调用中选择多个选项的select的表单序列化?

下面是我的$ .ajax调用,如何在数据部分中选择(多个)选定的值?

$.ajax({ type: "post", url: "http://myServer" , dataType: "text", data: { 'service' : 'myService', 'program' : 'myProgram', 'start' : start, 'end' : end , }, success: function(request) { result.innerHTML = request ; } // End success }); // End ajax method 

编辑我应该包括我理解如何使用此代码循环选择所选选项:

 $('#userid option').each(function(i) { if (this.selected == true) { 

但我如何将其纳入我的数据:部分?

如何使用数组?

 data: { ... 'select' : ['value1', 'value2', 'value3'], ... }, 

编辑 :对不起,这是代码,一些警告:

 'select' : $('#myselectbox').serializeArray(), 

为了使serializeArray()工作,所有表单元素必须具有name属性。 上面'select'的值将是一个包含所选元素的名称和值的对象数组。

 'select' : [ { 'name' : 'box', 'value' : 1 }, { 'name' : 'box', 'value' : 2 } ], 

产生上述结果的选择框将是:

  

感谢@Owen的回答,我得到了这段代码。

对于id =“mySelect”的选择框,multiple =“true”

  var mySelections = []; $('#mySelect option').each(function(i) { if (this.selected == true) { mySelections.push(this.value); } }); $.ajax({ type: "post", url: "http://myServer" , dataType: "text", data: { 'service' : 'myService', 'program' : 'myProgram', 'selected' : mySelections }, success: function(request) { result.innerHTML = request ; } }); // End ajax method 

表示所选多个选项集合的正确方法是使用数组 ,方法是使用[]后缀命名SELECT标记。
问题是jQuery方法serialize()没有正确处理它。
对于像这样的SELECT,infact:

  

serialize发送此数组:以这种方式接收PHP的[] = 0&a [] = 1&a [] = 2:

  [a] =>数组
     (
         [0] => 0
         [1] => 1
         [2] => 2
     )

真实价值丧失的地方。