xmlhttp request executed before getting the objects

T

tsangkinyip

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
 
T

Tom Cole

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();">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top