Whenever I try to search for result in my select2 ajax searchbar I receive the following message:
'The results could not be loaded'
Html:
<select class="js-data-example-ajax form-control" multiple="multiple"></select>
Javascript:
$('select').each(function(idx, ele) {
$(ele).select2({
theme: 'bootstrap4',
placeholder: ele.getAttribute('placeholder'),
ajax: {
url: '/product/api/search',
dataType: 'json' },
type: 'GET',
});
});
I think that my Ajax settings are wrong could you assist?
Your code should look like this. No GET method needed.
Also your problem might be in your source json format because select2 need own format with
results.Also you can use processResults or transform data into certain format.