I'm using the jQuery select2 plugin and trying to show data through Ajax request. But it is not calling the Ajax function, I have already tried everything but didn't work. Here's my code -
Html
<select class="form-control " multiple="" data-placeholder="Select Youtube Videos" aria-hidden="true"  name="collection_youtube_videos[]" id="collection_youtube_videos"></select>
Javascipt
$(document).ready(function(){
    $('#collection_youtube_videos').select2({
        ajax: {
            url: url,
            dataType: 'json',
            data: function (params) {
                var query = {
                    //trim the extra whitespace
                    search: params.term.replace(/\s+/g, " ").trim(),
                }
                // Query parameters will be ?search=[term]&type=public
                return query;
            },
            processResults: function (data) {
                // Transforms the top-level key of the response object from 'items' to 'results'
                return {
                    results: data.items
                };
            }
        }
    });
});
I'm using following versions
JQuery - 2.1.4
Select2- 4.0.0
The problem is that when I type something in the input box of select2, it didn't call this ajax request to get data. Can anyone help me with this?
 
     
    