myArr.forEach,无法读取未定义错误的属性“ forEach”
var hhtpistegi = new XMLHttpRequest();
var adres = "https://raw.githubusercontent.com/hiiamrohit/Countries-States-Cities-database/master/countries.json";
hhtpistegi.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var myArr = JSON.parse(this.responseText);
var bolgeSlc = document.getElementById('Bolgeler');
myArr.forEach(myArr => {
bolgeSlc.innerHTML += '<option> ' + myArr.name + ' <option>'
});
}
};
hhtpistegi.open("GET", adres, true);
hhtpistegi.send();
HTML代码连接
<div class="field">
<div class="control">
<select id="Bolgeler"></select>
<input type="button" onclick="UlkeleriGetir()" value="ulkleri listele" />
</div>
</div>