xmlhttp request executed before getting the objects

  • Follow


Hi there,

I have a diary page where I would like to fade in the text content and
an image when a user tries to click on a date in the calendar. Things
work fine offline, but when I upload the files to the server I've
found that the server is much slower than I've thought and the xmlhttp
request has been executed before getting the image and body objects,
which leads to a javascript error. May I ask what I can do to solve
the problem? Thanks in advance.

function showContent(xmlhttp, dt, day) {
	var date = dt.getDate() + '.' + (dt.getMonth()+1) + '.' +
dt.getYear();
	xmlhttp.open("HEAD", "diary/" + date + ".htm",false);
	xmlhttp.onreadystatechange=function() {
	if (xmlhttp.readyState==4) {
		if (xmlhttp.status==0 || xmlhttp.status==200){
..........
			document.all.content.src = "diary/" + date + ".htm";
			document.getElementById(day).innerHTML= date;
			document.getElementById("image").innerHTML= '<img src="images/' +
date +

'.jpg" height="150" width=150" name="u"
style="filter:alpha(opacity=0)">';
			window.clearInterval(window.timerID);
			window.timerID=window.setInterval("JM_fade(u,
document.frames('content').document.body)",5);
........
		}
                 ......................
 	xmlhttp.send(null);
}

Marco

0
Reply tsangkinyip (10) 3/26/2007 2:55:35 PM

On Mar 26, 9:55 am, tsangkin...@gmail.com wrote:
> Hi there,
>
> I have a diary page where I would like to fade in the text content and
> an image when a user tries to click on a date in the calendar. Things
> work fine offline, but when I upload the files to the server I've
> found that the server is much slower than I've thought and the xmlhttp
> request has been executed before getting the image and body objects,
> which leads to a javascript error. May I ask what I can do to solve
> the problem? Thanks in advance.
>
> function showContent(xmlhttp, dt, day) {
>         var date = dt.getDate() + '.' + (dt.getMonth()+1) + '.' +
> dt.getYear();
>         xmlhttp.open("HEAD", "diary/" + date + ".htm",false);
>         xmlhttp.onreadystatechange=function() {
>         if (xmlhttp.readyState==4) {
>                 if (xmlhttp.status==0 || xmlhttp.status==200){
> .........
>                         document.all.content.src = "diary/" + date + ".htm";
>                         document.getElementById(day).innerHTML= date;
>                         document.getElementById("image").innerHTML= '<img src="images/' +
> date +
>
> '.jpg" height="150" width=150" name="u"
> style="filter:alpha(opacity=0)">';
>                         window.clearInterval(window.timerID);
>                         window.timerID=window.setInterval("JM_fade(u,
> document.frames('content').document.body)",5);
> .......
>                 }
>                  ......................
>         xmlhttp.send(null);
>
> }
>
> Marco

Call your showContent function (or some other function that calls
showContent) from the onload event handler of the document body. This
method gets called after the body has been loaded.

<body onload="your_function();">

0
Reply Tom 3/26/2007 4:56:42 PM


1 Replies
107 Views

(page loaded in 0.062 seconds)

Similiar Articles:













7/9/2012 4:13:44 AM


Reply: