[geeklog-devel] Dynamic Comments...

Niels Leenheer niels at creatype.nl
Mon Jan 31 15:44:03 EST 2005

Vincent Furia wrote:

>I'm working on getting it past the prototype stage.  While it (just)
>works now, I need to do some modifications to make it integrate
>cleanly and to not be embarrassed by my code.  Hopefully I'll have it
>checked into CVS in the next couple days.
Vincent, great idea!

However, I can see a couple of problems with the code you are currently 

First of all, you are using a single XMLHttpRequest object without 
it from being called more than once. As a result it is possible to 
interrupt an
ongoing request. Try clicking on quickly on multiple triangles after 
each other,
without waiting for one to finish loading. Only the request clicked on 
last will
be honoured, the other ones will be 'loading' indefinately.

The solution to this problem would be to use an array and push each
request in it. Then use a timer to frequently look at this array, shift
one request of the bottom and execute it. Repeat until the array is

Secondly, there is a bug in the XMLHttpRequest implementation of Opera,
which basically requeres and extra check inside the onreadystatechange
function, otherwise it will be called multiple times after each other,
but only the first time with the proper responseText.

var inprogress = false;

function loadFragmentInToElement(fragment_url, element_id) {
    var element = document.getElementById(element_id);
    element.innerHTML = '<img src="/images/dynwait.gif" 
alt="Loading..."/>Loading ...';
    xmlhttp.open("GET", fragment_url);
    xmlhttp.onreadystatechange = function() {
        if (inprogress == true && xmlhttp.readyState == 4 && 
xmlhttp.status == 200) {
            inprogress = false;
            element.innerHTML = xmlhttp.responseText;
    inprogress = true;


More information about the geeklog-devel mailing list