1

I'm a bit lost with the JSON format I must return for Select2 so it works.

My returned JSON captured with fiddler:

Printscreen of my fiddler

And my Select2 setup (#FuncionarioID is a select input):

$('#FuncionarioID').select2({
ajax: {
    dataType: "json",
    url: "Ajax.ashx?Action=FuncionarioSelect2",
    results: function (data) {
        return { results: data };
    },
    cache:false
}

});

I've been reading questions about the same subject here in Stackoverflow, I tried the answers and none of them worked for me. Would you have any tip about solving this problem? I've already tried to return objects like this {"id":"1060","text":"teste 1"} and it didn't work too.

Thanks in advance for any help.

André Luiz
  • 6,642
  • 9
  • 55
  • 105
  • 1
    Have a look at the thread [http://stackoverflow.com/questions/20926707/how-to-use-select2-with-json-via-ajax-request][1] [1]: http://stackoverflow.com/questions/20926707/how-to-use-select2-with-json-via-ajax-request – Guilherme Câmara Aug 20 '15 at 18:15

1 Answers1

1

Try updating your function like this:

     $('#FuncionarioID').select2({
        ajax: {
            dataType: "json",
            url: "Ajax.ashx?Action=FuncionarioSelect2",
            cache: false,
            processResults: function (data, page) {
                return {
                    results: data
                };
            }
        }
    });