Click to See Complete Forum and Search --> : force a response from the server


tanfwc
09-12-2003, 01:34 AM
i need help...erm...i am a beginner in the javscript area...i wan to force the script to get a response from the server...sometimes...the server is too busy to give a response and it will displayed a x image...i wan to script to contiunely get the response from the server...this is the script i use...but it will only request twice...once the second times fail...it will fail...how do i request from the server until the server response and the script will stop getting the image from the server? this a special server...it will check the status of me and give back a image whether i am online or offline.


<IMG SRC="http://abc.com/abc">
border="0"
ALT="abc
onerror="this.onerror=null;this.src='http://abc.com/abc';"
width="21"
height="22"></A>

AdamGundry
09-12-2003, 10:39 AM
You should be able to replace this line

onerror="this.onerror=null;this.src='http://abc.com/abc';"

with this

onerror="this.src='http://abc.com/abc';"

Bear in mind that this could cause problems if the server will not respond at all, as the browser will keep trying to reload the image.

Adam

tanfwc
09-12-2003, 10:47 AM
erm...ok....i will try out later...thanx for responsing...

tanfwc
09-12-2003, 11:37 AM
i manage to get the on error thing works...erm...can i ask another qns...is that there is five server that i can get the images...how i try to request from the five server? erm...like if the first server is down...then request from the next server...

AdamGundry
09-12-2003, 01:59 PM
You should be able to use something like this (untested):
<script type="text/javascript">
var serverNum = 0;
var servers = ['http://www.server1.com/image', 'http://www.server2.com/image', 'http://www.server3.com/image',
'http://www.server4.com/image', 'http://www.server5.com/image'];
document.write('<img src="' + servers[0] + '" onerror="tryNextServer(this)">');

function tryNextServer(img){
serverNum++;
if (serverNum < servers.length){
img.src = servers[serverNum];
} else {
alert('Unable to download image!');
}
}
</script>

Adam

tanfwc
09-13-2003, 05:30 AM
this script work wonderfully well.....THANX