I am facing an issue, where my Select2 dropdown keeps showing "Searching..." (screenshot attached)
This is my JS code:
<script>
$(document).ready(function() {
$("#js-data-example-ajax").select2({
placeholder: 'Search for a stock',
ajax: {
url: "http://127.0.0.1:8000/stocks_list",
contentType: 'application/json',
dataType: 'json',
type: "GET"
},
});
});
</script>
HTML select field:
<select style="width: 300px;" id="js-data-example-ajax" name = "js-data-example-ajax" class="js-data-example-ajax"></select>
The endpoint in the AJAX call above returns a JSON object with "results" key and a list of objects for the search results (as expected by Select2), like below:
Response from local endpoint screenshot
I'm expecting to display the "text" fields as my dropdown results in the search results & I've followed the Select2 docs so far.