خطای Cannot read properties of undefined (reading 'forEach')

پرسیده شده
فعالیت 934 روز پیش
دیده شده 825 بار
0

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

    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);
        }
    }
فایل پیوست

Mahdiabedini
Mahdiabedini

18 مهر 00

0
حذف شده

سلام

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

 

 

 

 

’’’

فایل پیوست

مهرداد دادخواه

توسط

مهرداد دادخواه

20 مهر 00

0
حذف شده
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

توسط

Mahdiabedini

20 مهر 00