Select2 ajax init does nothing.
See original GitHub issueI’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
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (9 by maintainers)
Top Results From Across the Web
Select2 ajax does nothing - Stack Overflow
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...
Read more >Setting initial values on load with Select2 ajax AND templating
How do I set the first value shown in the select2 (before the user searches) and so that I can configure the templating...
Read more >Select2 dropdown broken after AJAX update - Toolset
Problem: I have implemented the select2.js library and replaced the select filters in my custom search View with select2 elements.
Read more >Options - Select2 - JeeSite
Due to a jQuery bug, nested options using data-* attributes do not work in jQuery 1.x. 1, <select data-ajax--url="http ...
Read more >Loading data remotely in Select2 with AJAX - Makitweb -
1. Table structure · 2. Database Configuration · 3. Download and Include · 4. HTML · 5. PHP – Return select2 data ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.