I'm experimenting a bit with AJAX and have successfully deployed a simple AJAX A-synced function, yet when I'm changing it to use callback method - suddenly, it takes ages to load (about 10 - 15 mins...). Here's the function that executes right away:
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's the way slower iteration using 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;
}
});
}
Other (perhaps) relevant details - the ajax.php file weighs merely 532 B, on my local test server both run more or less equally the same, the first function uses onscroll="ajaxf()" inside the body tag...
I was under the impression AJAX would be a little more snappy???