【发布时间】:2017-08-29 06:32:07
【问题描述】:
我在我的 wep 页面中使用了一个 select2 下拉菜单,我想使用 ajax 参数将选定的值发送到 servlet,我在 Ajax 下尝试过,但它不适合我。
我的 HTML Select 代码
<select class="form-control select2" id="color" name="color" multiple="multiple" data-placeholder="Select Colors">
<option>Red</option>
<option>Blue</option>
<option>Green</option>
<option>Gray</option>
</select>
我的Ajax代码:
$.ajax({
type: 'POST',
url: 'MyServerUrl',
data: {
color: $("#color").select2('data')
},
success: function (data, textStatus, jqXHR){
},
error: function (data, textStatus, jqXHR) {
}
});
有没有办法将 Direct 对象发送到 Ajax 参数?
【问题讨论】:
-
不确定 jQuery 的做法,但
document.getElementById('color'). value将获得选定的值。 -
你为什么不说问题是在 Java Servlet 中读取 POST 正文?
-
是的,实际上我正在 servlet 中访问该参数值:` String[] outerArray = request.getParameterValues("color");` 但没有进入 outerArray
标签: javascript jquery ajax jquery-select2