我在Internet Explorer中遇到问题,我的forEach函数在谷歌浏览器和Microsoft Edge中正常工作,但是Internet Explorer抛出以下错误: 我的代码:
function jsFiltreleme(GelenDeger) {
$('#myDiv').html('');
var cnt = 1;
$.ajax({
type: 'GET',
url: '/Ajax/ContractedServiceAdd2?serviceName=' + GelenDeger.serviceName + '&&cityCode=' + GelenDeger.cityCode + '&&countryCode=' + GelenDeger.countryCode + '&&markCode=' + GelenDeger.markCode + '',
dataType: "json",
success: function (response) {
response.forEach(acente => { //Problem is Here line 692
const $div = $('<div></div>').addClass("well well-sm").attr('style', 'border-style:ridge;');
$div.html(`
<div class = "numberCircle"> ` + cnt++ + ` </div> <strong>Acente Adı : </strong> ` + acente.name + `<br>
<strong>Yetki :</strong> ` + acente.category + `<br>
<strong>Adresi : </strong> ` + acente.address + `<br>
<strong>Telefon :</strong> ` + acente.phone + `<br>
<a href=\"mailto:`+ acente.email + `\"><strong> >E-Mail Gönder</strong><br>
<a href=\"https://maps.google.com/maps?q= `+ acente.lat + "," + acente.lng + `\"><strong> >Yol tarifi al</strong>
`);
$("#myDiv").append($div);
});
if (response.length == 0) {
alert("Kayıt Bulunamadı");
}
},
});
}
答案 0 :(得分:0)
arrow function expression doesn't support IE browser,您可以按以下方式更改代码:
response.forEach(function (acente) { //Problem is Here line 692
});
if (response.length == 0) {
alert("Kayıt Bulunamadı");
}
修改:
这次不更改,是说第693行出现javascript严重错误
此问题与有关动态添加html元素的代码有关。您可以先构建DOMString,然后使用append method将字符串插入div容器。像这样的代码:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="output">
</div>
<script>
var response= [your response array];
var cnt = 1;
response.forEach(function (acente) {
var textnode = document.createTextNode(acente);
document.getElementById("output").appendChild(textnode);
var newdiv = "<div class = 'well well-sm' style='border-style:ridge;'><div class = 'numberCircle'> " + cnt++ + " </div> <strong>Acente Adı : </strong> " + acente.name + "<br />" +
"<strong>Yetki :</strong> " + acente.category + "<br>" +
"<strong>Adresi : </strong> " + acente.address + "<br>" +
"<strong>Telefon :</strong> " + acente.phone + "<br>" +
"<a href='mailto:" + acente.email + "'><strong> >E-Mail Gönder</strong>" + "<br/>" +
"<a href='https://maps.google.com/maps?q= " + acente.lat + "," + acente.lng + "'><strong> >Yol tarifi al</strong>" +
"</div>"
$("#output").append(newdiv);
});
</script>