After tinkering with AJAX, I managed to successfully implement a basic AJAX A-synced function. However, when attempting to switch it over to use a callback method, the loading time suddenly increases drastically (taking about 10-15 minutes...). Here's the initial function that works efficiently:
function ajaxf() {
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200 && document.getElementById("icons")==null)
{
document.getElementById("text-12").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://some-url/ajax.php",true);
xmlhttp.send();
}
And here is the much slower version utilizing a callback function:
function ajaxf(url,cfunc) {
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
document.body.onscroll = function ajaxb() {
ajaxf("http://some-url/ajax.php",function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200 && document.getElementById("icons")==null)
{
document.getElementById("text-4").innerHTML=xmlhttp.responseText;
}
});
}
Some other potentially relevant information - the ajax.php file is only 532 B in size, on my local test server both functions perform relatively similarly, and the first function uses onscroll="ajaxf()" within the body tag...
I had expected AJAX to be a bit more responsive. Any ideas why the slowdown occurs?