Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When should i show loading ico when using AJAX?

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
When should i show a loading icon for ajax, and whats the best method for showing an animated gif when loading?
 
if using prototype it might look something like this

Code:
var myAjax = new Ajax.Updater(
            target, 
            url, 
            {
                method: 'get', 
                parameters: pars,
                onComplete:function(request){Element.hide('spinner')},
                onLoading:function(request){Element.show('spinner')}
            });
 
Would this work? I can't really test it at the point in time, because its localhost and there is not loading :)


Code:
var LoadHTMLHttp = null;
function LoadHtml(iCall,sSaveThis,intId) {
// show Loading icon
	document.getElementById('Layer1').style.display="";
    LoadHTMLHttp = createRequestObject();
    var url="ajax_display.asp?call=" + iCall + "&save=" + sSaveThis + "&id=" + intId
    LoadHTMLHttp.open('GET', url, true);
    LoadHTMLHttp.onreadystatechange = getLoadHTMLHttpResponse;
    LoadHTMLHttp.send('');
}

function getLoadHTMLHttpResponse() {
    if (LoadHTMLHttp != null)
        if (LoadHTMLHttp.readyState == 4)
            if (LoadHTMLHttp.status == 200)
                document.getElementById('viewsubtopic').innerHTML = LoadHTMLHttp.responseText;

// hide Loading icon				document.getElementById('Layer1').style.display="none";

}
 
simplfy your life use prototype

Code:
var pars = "call=" + iCall + "&save=" + sSaveThis + "&id=" + intId
var myAjax = new Ajax.Updater(
            "viewsubtopic", 
            "ajax_display.asp", 
            {
                method: 'get', 
                parameters: pars,
                onComplete:function(request){Element.hide('Layer1')},
                onLoading:function(request){Element.show('Layer1')}
            });
 
steven,

You show these great examples, but provide no information about the libraries we need to use to get them to work.

In your example above, "Ajax" is not defined anywhere, so the code will clearly not work. Nor are "iCall", "sSaveThis", "intId", or "Element" defined.

Don't get me wrong - I'm not simply trying to pick holes in your code... just point out that some users may not realise that your code wont work as-is, without extra libraries, so it might be good to give information about these when posting snippets that require them.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
steven290 said:
simplfy your life use prototype
Whilst frameworks (like the one you have mentioned twice now) can be very useful in speeding up development time, they tend to require you learn their own data structures and methods... and they usually have quite particular ways of doing things.

I would rather learn the language - than learn how to implement some niche product based on that language. You end up with full control - and full understanding.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Being new to ajax world as some of you know, I think it would be a bad idea for me to jump into something such as prototype as this point, however I will spurl the link for a later date and look into it, but I feel that the "old school" way for now is efficient for what i am doing.

Regards,
Jason
 
thats cool but i would still in the prototype js in you documents. besides the ajax stuff it has some good functions

ex.

Code:
old way
document.getElementById('Layer1')

prototype
$('Layer1')

even further
document.getElementById('Layer1').style.display="";
to
Element.hide('Layer1');
or
Element.toggle('Layer1');

not to mention the many other functions, its really helped me even when not running ajax scripts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top