Я делаю это:
сначала у вас есть скрытый div с загрузкой, если в нем, и кнопкой загрузки:
<div id="displayDiv" style="display: none">
<img id="loadingGif" src="loadingGif" style="display:none"; />
<div id="actualContent" style="display:none" />
</div>
<input type="button" id="loadButton" />
Тогда у вас есть код JS (я использую jQuery)
<script type="text/javascript">
$(document).ready( onDocumentReady); // this runs before page load
function onDocumentReady()
{
$('#loadButton').click( onLoadClick ); //assign action on button click
}
function onLoadClick()
{
$('#loadingGif').show(); // show the loading gif. It won't show as long as it's parent is hidden
$('#actualContent').hide(); // hide the actual content of the response;
$('#displayDiv').show(); // display the div
$.get("test.php", onRequestComplete ); // make the ajax request to the stand alone PHP file
//so as long as the content loads, the loading gif will show;
}
function onRequestComplete( data )
{
$('#loadingGif').hide();
$('#actualContent').html( data );
$('#actualContent').show();
}
</script>
Итак. У вас есть контейнер "displayDiv"; внутри у вас есть изображение «loadingGIf» и другой контейнер «actualContent»; Когда вы нажимаете кнопку загрузки, появляется большой контейнер с загрузочным GIF, уведомляющий пользователя о том, что что-то загружается. Когда содержимое загружено, вы просто скрываете loadingGif и отображаете информацию в gif «actualContent». В test.php вы просто повторяете то, что должно появиться в div. Я рекомендую использовать JSON, но вы узнаете об этом подробнее.
Надеюсь, это поможет.