Well in a typical sort of AJAX call like you describe, a function is passed some data as to the nature of the request and an id of an element (or the element itself) to place the results of the request in once it's fulfilled. The function determines the Http Request method that the browser supports and then processes it, generally with another function or some code attached in some way to the request's onreadystatechange event to populate the element on a readyState value of 4 by overwriting it's innerHTML property with the new data.
So you have something like so:
Code:
function loadXmlHttp(url_or_database_query, id){
. . .
}
Right at the beginning of that function, you can have some code to place a loading icon like:

into the element that will receive the request data once it is processed.
Now the exact nature of that code would depend upon a number of things. But one possibility would be:
Code:
function loadXmlHttp(url_or_database_query, id){
var loadingarea = document.getElementById(id),
loadingimg = document.createElement('img');
loadingimg.src = 'loading.gif';
while(loadingarea.lastChild) loadingarea.removeChild(loadingarea.lastChild);
loadingarea.appendChild(loadingimg);
. . .
}
Bookmarks