So, I'm hoping someone can help me with this. I currently run a site that does a lot of database searches, and (for something to do) I decided to ajaxify the site. Now, I found a function that loads a page into a div, which seems to work fine...except when loading my main search pages. When I load one of those the script seems to display the page before the results have come back from the database, so I get an empty table. If I access the search page directly (without going through the ajax bit) it works fine.
Here's the loading function I'm using:
function LoadPage(page,usediv) {
// Set up request varible
try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { alert("Error: Could not load page.");}
//Show page is loading
document.getElementById(usediv).innerHTML = '<center><br><br><img src="loading.gif"><br><br></center>';
//scroll to top
scroll(0,0);
//send data
xmlhttp.onreadystatechange = function(){
//Check page is completed and there were no problems.
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
//Write data returned to page
document.getElementById(usediv).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", page);
xmlhttp.send(null);
//Stop any link loading normaly
//return false;
}
And if you want example pages, I can link you to them....I'm just wary of posting links here in case it looks like I'm plugging the site.