0
I need to make sure that when completing the requisition AJAX the jquery insert the options in a select but when doing so options do not appear when clicking but when inspecting shows that they are present in the select
Request script:
$(document).ready(function(){
$.get("http://localhost/infinityy/assets/php/list-categories.php", function(data){
categories = JSON.parse(data);
var select = $("#category");
$(categories).each(function(){
var option = $("<option>");
option.attr("value", this.id);
option.text(this.name);
console.log(option);
select.append(option);
});
});
});
Select:
<form action="assets/php/add-category.php" method="post">
<div id="form" class="form-group">
<div class="form-group">
<label>Categoria <a href="#" class="add-category"><i class="fa fa-plus" aria-hidden="true"></i></a></label>
<select id="category" name="category" class="selectpicker" data-title="Categoria" data-style="btn-default btn-block" data-menu-style="dropdown-blue" required>
</div>
</div>
</form>
Result even clicking does not show the options
**When inspecting the Select: **
Since you are using php, is it possible to do what you want with a load, it would be interesting for you? Or it has to be using append?
– David Alves
What would Load be?
– Luhan Salimena
Another javascript function to load options in another way. If this is a viable option, I can give you an answer explaining how to use this function.
– David Alves
I don’t know that function, could you show me?
– Luhan Salimena