I'm needing to download names of cities in a comboBox Select2 via ajax, but so far it has not worked. many examples in internet search, but not understand them too.
$(document).ready(function() {
var url = "http://localhost:8000/api/city?";
$("#city").select2({
minimumInputLength: 1,
ajax: {
url: url,
dataType: 'json',
type: "GET",
delay: 500,
data: function (term) {
return {
city: term
};
},
results: function (data) {
console.log(data);
return {
results: $.map(data, function (item) {
return {
text: item.text,
id: item.id
}
})
};
}
}
});
});
y este es el código json que devuelve mi servidor con la consulta realizada:
[{ "id": 1, "text": "Capital, Córdoba, Argentina" }]
Dice "Searching...." y luego "No results found"
Really, Thanks!