Find jobs - Myspace Images - Debt Consolidation - Web Hosting - Skype

PDA

View Full Version : [ajax related] Why don't i see my loading.gif ?


123GoToAndPlay
Aug 9th 2007, 1:22 am
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";
}
}
}


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>

Which readystate do i need to check to show the loading.gif????

123GoToAndPlay
Aug 9th 2007, 2:01 am
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";
}
}
//}

gibex
Aug 10th 2007, 2:56 pm
use prototype to make your things easier.

123GoToAndPlay
Aug 16th 2007, 7:32 am
@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});


Which other ajax libs do you recommend???

amnezia
Aug 16th 2007, 7:36 am
Make sure you preload the animated.gif before you display it.

ritadebock
Aug 22nd 2007, 5:41 am
Make sure you preload the animated.gif before you display it.

preloading???? how?

123GoToAndPlay
Sep 10th 2007, 7:05 am
@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];}}
}


and


<body onload="MM_preloadImages('loadng.gif');"


regards