Select2 multiselect ajax php

I am trying to populate my multiple select2 with ajax, but I have no return in the field.

What is my HTML code:

<input type="hidden" id="instituicaoSel" tabindex="-1" class="select2-offscreen" value="">

JavaScript:

$('#instituicaoSel').select2(
{
    placeholder: "Escolha uma ou mais instituições",
    minimumInputLength: 1,
    width: '100%',
    multiple: true,
    ajax: {
        url: basepath + "perfil/buscarInstituicoes",
        dataType: 'json',
        quietMillis: 100,
        data: function (term, page) {
            return {
            q: term, 
            page_limit: 10,
            page: page 
            };
        },
        results: function (data, page)
        {
            var more = (page * 10) < data.total;
            return { results: data.results, more: more };
        },
        dropdownCssClass: "bigdrop"
    }
});

And this is my ajax result:

[{"result":[{"id":"1","text":"Ag\u00eancia Brasileira de Desenvolvimento Industrial"}],"total":1}]

The value that I put in the placeholder is not displayed.

+3
source share
1 answer
<select id="sel" placeholder="MyPlaceHolder">
  <option></option>
  <option>Option value</option>
</select>

you need to add <option></option>

example http://hromnik.com/web/select2/

and solution: http://hromnik.wordpress.com/2012/10/18/select2-placeholder-does-not-work-solution/

0
source

All Articles