This is what I have
$( "#codigo" ).select2({
ajax: {
url: "getEmpleados.php",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term // search term
};
},
processResults: function (data, page) {
return {
results: $.map(data, function (item) {
return {
id: item.id,
text: item.text,
}
})
};
},
cache: true
},
minimumInputLength: 1
});