I have a PHP file listing the files in the directory and I wrote this javascript to complete the rest of it:
$.get('getPage.php?id=index', function(contents){
contents = contents.split(';');
for(var i=0; i<contents.length; i++){
alert(i);
if(contents[i] != ''){
$.get('pages/' + contents[i], function(data){
pages[i] = data;
alert('pages[' + i + '] = ' + data);
});
}
}
});
As you can see, I have a few alerts in there. The for loop works fine. It counts from 0 to 3. But for some reason the second alert always displays "pages[4] = (the page data)" and it does that for every page (sets the content's to pages[4]). Making the pages array undefined, undefined, undefined, and the last retrieved page's contents. What gives?

New Topic/Question
Reply




MultiQuote



|