php - Trying to propagate a select2 dropdown from an API in Laravel
I am having trouble propagating a selct2 dropdown from data from an API. I am using this example from here
https://select2.org/data-sources/ajax
as well as from here
Basically, my select2 dropdown is showing, but it is empty.
Here is my select 2 HTML code
<select class="form-control" name="shortcode" id="formControlSelectShortCode" required>
Here is my script
$('#formControlSelectShortCode').select2({
ajax: {
url: 'https://api.github.com/search/repositories',
dataType: 'json'
}
});
I used the 2 pages above as a reference, but the code looks ok from what i can see. it might be an issue with the api, however, the sample on the page works fine.
Answer
Solution:
Here is the full code for select2 dropdown from exaple you provided.
https://select2.org/data-sources/ajax#additional-examples
You are missing providing search parameter q since github's api returns error message if q is not provided.
Source