I have a page, videos.php, that loads a video feed through Ajax. On the php ajax page, video_feed_ajax.php, it looks through an array creating a object for each video. However, the current way I have the JS written, it only displays the video_feed_ajax.php when its completley loaded (when its looped through the entire array).
->Is there a way to display the video_feed_ajax.php each time it goes through the loop, so the videos are shown as it loops through instead of just at the end?
The portions of my JS that apply:
xmlhttp.onreadystatechange=stateChangedUsersAddVideoFeed;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
function stateChangedUsersAddVideoFeed()
{
document.getElementById("add_video_feed").innerHTML=xmlhttp.responseText;
document.getElementById('add_video_feed_load_img').style.display='none';
}
You could call the flush function inside your loop in PHP to immediately send the echoed mark-up.
But if your loop is taking long enough to be a nuisance there must be something wrong with it – unless you just want the visual effect of progressive loading, in which case you should simply animate that after receiving the whole response. There is no point in streaming just a few kbs.