I using select2 version 4 using ajax for my option. whenever i try to do some searching, select2 will show 'The results could not be loaded'.
$( "#thisid" ).select2({
minimumInputLength: 2,
ajax: {
url: "search-product.php",
dataType: 'json',
data: function (params) {
return {
q: params.term // search term
};
},
processResults: function (data) {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return {
results: data
};
},
cache: true
},
minimumInputLength: 2
});
Browsers
Operating System
This appears to be more of a usage question than a bug report or common feature request. As we continue to keep the Select2 issue tracker geared towards these two areas, bug reports and common feature requests, we are redirecting usage questions to other communities such as the mailing list, IRC, or Stack Overflow.
in processResult using
var newData = [];
for (var i = 0; i < data.length; i++) {
newData.push({
id: data[i].ID, //id part present in data
text: data[i].Nome //string to be displayed
});
}
return { results: newData };
@cesguto it's just no change
Most helpful comment
in processResult using
var newData = []; for (var i = 0; i < data.length; i++) { newData.push({ id: data[i].ID, //id part present in data text: data[i].Nome //string to be displayed }); } return { results: newData };