question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select2 ajax init does nothing.

See original GitHub issue

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           

    });

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
alexweissmancommented, Sep 25, 2017

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.

1reaction
alexweissmancommented, Sep 25, 2017

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found