[ajax related] Why don't i see my loading.gif ?

Discussion in 'JavaScript' started by 123GoToAndPlay, Aug 9, 2007.

  1. #1
    
    function output(http_request,layerName) {
    			
    			//Check to see if the XmlHttpRequests state is finished.
    			if (http_request.readyState == 4) {
    			//Set the contents of our span element to the result of the asyncronous call.
    				 if (http_request.status == 200) {
    					document.getElementById(layerName).innerHTML = http_request.responseText;
    				 } else if((http_request.readyState == 1) ||(http_request.readyState == 2)){
    					document.getElementById(layerName).innerHTML = "loading...<img src=\"loading.gif\"/>";
    				} else {
    					document.getElementById(layerName).innerHTML = "Sorry, currently unavailable";
    					}
                }
    		}
    
    Code (markup):
    I am loading a file with a big image. I can see the image, but not the loading.gif and loading text
    
    <span id="test" onclick="makeRequest('bigimg.php','test')">
    show biggie
    </span>
    
    Code (markup):
    Which readystate do i need to check to show the loading.gif????
     
    123GoToAndPlay, Aug 9, 2007 IP
  2. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ah this seems to work
    
    //Called every time our XmlHttpRequest objects state changes.
    		function output(http_request,layerName) {
    			
    			//Check to see if the XmlHttpRequests state is finished.
    			if((http_request.readyState == 1) ||(http_request.readyState == 2)){
    					document.getElementById(layerName).innerHTML = "<span align=\"center\">Loading<img src=\"loading.gif\"/></span>";
    					
    			} else if (http_request.readyState == 4) {
    			//Set the contents of our span element to the result of the asyncronous call.
    				 if (http_request.status == 200) {
    					document.getElementById(layerName).innerHTML = http_request.responseText;
    				 } 
    			} else {
    				document.getElementById(layerName).innerHTML = "Sorry, currently unavailable";
    				}
                }
    		//}
    
    Code (markup):
     
    123GoToAndPlay, Aug 9, 2007 IP
  3. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #3
    use prototype to make your things easier.
     
    gibex, Aug 10, 2007 IP
  4. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    @gibex, tx for the tip

    I am trying it out. Do you know how to pass a php-array in
    
    pars = array
    new Ajax.Updater('div-name', file, { method: 'post', parameters: pars});
    
    Code (markup):
    Which other ajax libs do you recommend???
     
    123GoToAndPlay, Aug 16, 2007 IP
  5. amnezia

    amnezia Peon

    Messages:
    990
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Make sure you preload the animated.gif before you display it.
     
    amnezia, Aug 16, 2007 IP
  6. ritadebock

    ritadebock Peon

    Messages:
    344
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    preloading???? how?
     
    ritadebock, Aug 22, 2007 IP
  7. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    @ritadebock,
    I think amnezia means something in the line
    
    
    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    
    Code (markup):
    and

    
    <body onload="MM_preloadImages('loadng.gif');"
    
    Code (markup):
    regards
     
    123GoToAndPlay, Sep 10, 2007 IP