[Answered ]-TypeError: Cannot read properties of undefined (reading 'forEach') with ajax method

1👍

use the optional chaining (?.) operator to check if the variable is not null before accessing it.

change :

data.forEach(el => {.....

to :

data?.forEach(el => {.....

and make sure to access div correctly you have to :

change :

   <div class="quiz-box"></div>

to :

<div id="quiz-box"></div>
👤monim

Leave a comment