🎉 سال نو، مهارت نو، مشاوره رایگان نقشه راه برنامه نویسی (آفر ویژه ثبت نام قبل از افزایش قیمت 🔥)
۰ ثانیه
۰ دقیقه
۰ ساعت
۲ Mahdiabedini
خطای Cannot read properties of undefined (reading 'forEach')
جامعه جاوا اسکریپت ایجاد شده در ۱۸ مهر ۱۴۰۰

استاد من دقیقا مثل شما کد نوشتم ولی موقع اجرا این پیغام خطا را به من میده چرا کدی که من نوشتم این هستش؟

    let xhttp = new XMLHttpRequest();
    xhttp.open('GET','https://mocki.io/v1/d4867d8b-b5d5-4a48-a4ab-79131b5809b8');
    xhttp.send();
    function processResult(result){
         result.forEach(function (element){
             console.log(element);
         })
    }
    let response;
    xhttp.onreadystatechange = function (){
        // console.log(this);
        if (this.readyState ==4  && this.status == 200){
            console.log("success");
            reponse = JSON.parse(this.response);
            processResult(response);
        }
    }

سلام

قبل از اینکه تابع processResult را صدا بزنید از response یک لاگ بگیرید و نتیجه را اینجا بذارید ..

 

 

 

 

’’’

حسین دادخواه ۲۰ مهر ۱۴۰۰، ۰۱:۰۶
let xhttp = new XMLHttpRequest();
xhttp.open('GET','https://mocki.io/v۱/d۴۸۶۷d۸b-b۵d۵-۴a۴۸-a۴ab-۷۹۱۳۱b۵۸۰۹b۸');
xhttp.send();
function processResult(result){
    result.forEach(function (element){
        console.log(element);
    })
}
let response;
xhttp.onreadystatechange = function (){
    // console.log(this);
    if (this.readyState ==۴  && this.status == ۲۰۰){
        console.log("success");
        reponse = JSON.parse(this.response);
        console.log(response);
        processResult(response);
    }
}
Mahdiabedini ۲۰ مهر ۱۴۰۰، ۰۵:۱۱