【发布时间】:2014-05-11 17:55:25
【问题描述】:
我在 HTML 表单中使用 Select2 jQuery 插件通过 ajax 调用获取远程数据。此功能运行良好。
但是在提交表单的时候,Select2元素中选择的值在表单POST数据中是不可用的。
我能够获取有关单选按钮和提交按钮的数据,但不能获取与 Select2 绑定的用户框元素。
应该怎么做才能获取表单中选择的数据以在PHP中进行处理?
<form name='adminForm' method="post">
<input type="radio" name="type" value="all"> 1 <br/>
<input type="radio" name="type" value="from"> 2 <br/>
<input type="radio" name="type" value="to"> 3 <br/>
<div id="userbox"></div>
<input type="submit" value="Submit" name="searchMessages">
</form>
下面是我使用的 jQuery 代码。
$("#userbox").select2({
minimumInputLength: 1,
formatResult: productFormatResult, // Not provided here
formatSelection: productFormatSelection, // Not provided here
ajax: {
url: "/url/path",
data: function (term, page) {
return {
q: term,
};
},
results: function (data, page) {
return {results: data};
}
},
escapeMarkup: function (m) { return m; }
});
【问题讨论】:
标签: jquery jquery-select2