select2: Select2 ajax init does nothing.
I’m having an issue with the select2 (4.0.3) ajax call for the “type ahead” function. I originally had this as an input then changed it to a select to support the 4.0 requirement. I’ve confirmed its hitting the initialize for Select2. I’ve also confirmed that the url passed is good. Everything I have should be working based on the documentation. What am I missing? I appreciate a second set of eyes. Thanks for your help.
HTML
<select
id="medList2"
placeholder="Drug"
class="select2"
style="width: 200px;"
data-sequence="80"
data-parent-id="4"
data-id="80"
data-label="Drugs"
data-bind-0="4-80"></select>
Javascript
$('#medList2').select2({
ajax: {
url: '/path/todata/',
dataType: 'json',
delay: 250,
type: "POST",
// id: getUnid(),
// contentType: "application/json",
data: function (term) {
return {
Prefix: term
};
},
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.Text,
id: item.ID
}
})
};
},
cache: true
},
placeholder: 'Choose Meds',
minimumInputLength: 2
});
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (9 by maintainers)
Yes, the sample you sent appears to be functioning properly. I can see it making the AJAX requests as I type (though the URL itself is returning 404 errors), and updating the search results message accordingly.
@codeincolor you need to use three backticks, on their own line, to format code blocks in Markdown. See this guide. I’ve fixed it for you this time.