无法从select2发送多个选项,使用fromdata上传文件

时间:2016-08-26 10:20:33

标签: php jquery

我有html select2,它可以选择多个选项:

{% extends "base.html" %}

{% block title %}Index{% endblock %}

{% block head %}
    <!-- some content here -->
{% endblock %}

{% block content %}
     <!-- some content here -->
{% endblock %}

这个jquery:

enter image description here



但在PHP中,它只显示了1个选项。如何解决?

1 个答案:

答案 0 :(得分:1)

将下拉列表名称更改为数组:

<select name="for" id="for" class="for" multiple="multiple" placeholder="For" style="width: 92%">

<select name="for[]" id="for" class="for" multiple="multiple" placeholder="For" style="width: 92%">

JS:

var selectedOpt = $('#for').val();  // it will return an array of selected options
// Now use the selectedOpt array in your ajax call