Reputation: 7302
I'm a bit lost with the JSON format I must return for Select2 so it works.
My returned JSON captured with 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.
Upvotes: 1
Views: 223
Reputation: 36
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
};
}
}
});
Upvotes: 1