I'm facing an issue with my ajax request where I am unable to populate the options of a select tag. This problem is occurring in multiple blocks where the select tag serves the purpose of choosing a type of product.
Here is how my select tag looks like:
<select class="form-control" name="type" id="select-types">
</select>
This is the ajax request I am using:
function getTypes() {
$.ajax({
url: `/types/json`
}).done(function(res){
console.log(res)
})}
The response "res" has the following structure:
{types: [{"id":1,"name": Name}, ...]}
Imagine having 5 blocks each containing the same select element.
1. How can I only fill the last one?
2. What is the best approach to populating it correctly?