I try to add dynamically select options, when the user inserts 3 characters minimum. It works fine, server returns the result in JSON format but I have a problem adding the select inputs. The json
that is returned is like:
{
"id" : 39,
"description" : "125"
}
And the JS code I have written is :
$(".getTargetId").select2({
ajax: {
url: //url,
dataType: 'json',
type: "POST",
delay: 250,
data: function (params) {
return {
targetId: params.term
};
},
processResults: function (data) {
console.log("data = " + data);
return {
results: $.map(data, function (item) {
return {
text: item.description,
id: item.id
};
})
};
},
cache: true
},
allowClear: true,
minimumInputLength: 3
});
I checked and server sends the JSON string successfully. The log message that is printed in the browser console is data = [object Object]
The problem is that message I get on the select input is that none results were found… What I am missing?
I am using Select2 v4.0.10