Get results from Ajax Transport?

My Select2 function.

This is my Select2 function. I’m using the Ajax Transport so I can use my own search function and return the results , the documentation does not mention what format it need to be. So it’s only string now “text1 , text2, text3”

My function is working and accessed , it’s all ok, but no results on the page

But I’m unable to fill the select html on the page :frowning:

Help please :frowning:

$(".select2").select2({
theme: “bootstrap4”,
placeholder: “Type what you want”,
ajax: {
transport: function (params, success, failure) {
if (params.data.term != undefined) {
if (params.data.term.length >= 2) {
return searchOnline(params.data.term);
}
}
},
processResults: function (data) {
return { results: data };
},
},
});

The documentation for the Select2 data format from an AJAX data source is here: The Select2 data format.

1 Like