Here is a loop in my code in which i send ajax call to some API to fetch data. it works fine for first iteration(outer loop), but show error on 2nd and onward . here is code:
$.ajaxSetup({ cache: true, jsonpCallback: 'quranData' }); // define ajax setup
for (var counter = 1; counter < 4; counter++) //outer loop
{
$.getJSON("http://api.globalquran.com/surah/"+counter+"/quran-simple?jsoncallback=?", {
format: "jsonp"
}, function (Obj) {
$.each(Obj.quran, function (i, by) {
$.each(by, function (verseNo, line) {
var obj = {
'ayah_no': line.ayah_no,
'ayah': line.ayah,
'surah': line.surah,
'verse': line.verse
};
c++;
num++;
things.push(obj);
});
});
});
} //outer loop ends
Error:
> Uncaught TypeError: Property 'quranData' of object [object Object] is not a function
this happens only when i run outer loop, how to fix it ?