Is this an acceptable thing to do with ajax?

Wise Guy
Soldato
Joined
23 May 2009
Posts
5,748
I don't know anything about javascript really but I managed to hack out a script that shows/hides text from a database.

It changes the display:none part of a div, to either show or hide an external php page called by xmlhttp and put in to the <div> with innerHTML. I noticed that if I put a sleep() pause in the external php page, the JS will show what was already in the <div>.

Is it ok to put a preloader gif in the <div> so it will show, if the external page is slow to load?


PHP:
<div id="28" style="display:none;"><img src="loading.gif" /></div>

The external php page output replaces the <img> when the script is run.
 
Yes I don't really see why not, I've done this before. Be aware that in the improbable event that the AJAX request does not return, that loading image will just sit there.

Also, you might want to look into using the jQuery library - it makes doing AJAX so much nicer than in straight JS.
 
Back
Top Bottom