I want to create select2 with content flag, name country, and calling Codes. I have some problems with my code because I can't show the output what I want.
var countriesList = "https://restcountries.com/v2/all";
$.ajax({
type: "GET",
url: countriesList,
dataType: "json",
success: function (response) {
$(".js-data-example-ajax").select2({
data: response.map((e) => ({
id: e.alpha2Code,
text: e.name,
})),
width: 300,
dropdownAutoWidth: true,
});
},
error: function () {},
complete: function () {},
});
from this enter image description here
to this enter image description here