[thelist] Javascript: run a function once a function is complete

ben morrison morrison.ben at gmail.com
Mon Jan 9 08:30:43 CST 2006

> Depends, if A is an AJAX load thingy then you need to monitor the
> readyState to see when the whole thing was loaded (4), and also
> provide a timeout fallback in case it simply takes too long.
Yes im currently using the protoype ajax call so im using

onComplete: showResponse

which is my function:

 function showResponse(originalRequest) {
            //put returned XML into xmlDoc for processing...
             var xmlDoc = originalRequest.responseXML;
             xmlDoc = xmlDoc.documentElement;

              //Regular expression used to match any non-whitespace
            var notWhitespace = /\S/;
            for (var i=0; i<xmlDoc.childNodes.length; i++) {
                  if ((xmlDoc.childNodes[i].nodeType ==
             for (var i=0; i<xmlDoc.childNodes.length; i++) {
                objPrefs.prefs[i] = xmlDoc.childNodes[i].nodeName;
                  objPrefs.prefValue[i] = xmlDoc.childNodes
             objPrefs.loaded = true;

My other function needs to make sure this has worked before i call it

    //return the value of the preference
    get: function(prefname) {
        if (this.loaded){
            var i = this.prefpos(prefname);
            if (i >=0) {
                return this.prefValue[i];
            } else {
                return "BadFieldName!";
        } else {
//try and make sure its been transformed
            setTimeout("objPrefs.get('"+prefname+"')", 1000);


As you can see there is too much recursion going on there, any ideas?


More information about the thelist mailing list