ktsixit
12-10-2008, 12:57 PM
var all_news = new LoadVars();
all_news.load("http://localhost/website/news.php?");
all_news.onLoad = function(success){
if(success){
for(i=1; i<=all_news.total; i++) //all_news.total = 3
{ var this_new = new LoadVars();
this_new.load("http://localhost/website/news.php?id="+i);
trace("http://localhost/website/news.php?id="+i);
this_new.onLoad = function(success){
if(success){
trace(this_new.news_title.toString());
trace(this_new.news_text.toString());
}else trace("error");
}
}
}else trace("error");
}
this code is about getting data from a php file. The output it gives is:
http://localhost/website/news.php?id=1
http://localhost/website/news.php?id=2
http://localhost/website/news.php?id=3
undefined
undefined
undefined
undefined
title 3
text 3
but why is this happening? Shouldn't it be like this?>>
http://localhost/website/news.php?id=1
undefined
undefined
http://localhost/website/news.php?id=2
undefined
undefined
http://localhost/website/news.php?id=3
title 3
text 3
all_news.load("http://localhost/website/news.php?");
all_news.onLoad = function(success){
if(success){
for(i=1; i<=all_news.total; i++) //all_news.total = 3
{ var this_new = new LoadVars();
this_new.load("http://localhost/website/news.php?id="+i);
trace("http://localhost/website/news.php?id="+i);
this_new.onLoad = function(success){
if(success){
trace(this_new.news_title.toString());
trace(this_new.news_text.toString());
}else trace("error");
}
}
}else trace("error");
}
this code is about getting data from a php file. The output it gives is:
http://localhost/website/news.php?id=1
http://localhost/website/news.php?id=2
http://localhost/website/news.php?id=3
undefined
undefined
undefined
undefined
title 3
text 3
but why is this happening? Shouldn't it be like this?>>
http://localhost/website/news.php?id=1
undefined
undefined
http://localhost/website/news.php?id=2
undefined
undefined
http://localhost/website/news.php?id=3
title 3
text 3