Hi All,

I thought I had things sussed after the answer in http://www.webdeveloper.com/forum/sh...allback-jQuery - but my code still isn't working as previously thought. To expand on my previous code / question:

Code:
        function processThisSuite(suite, suitenumber)
        {
            //var request = $.post("initiateMars", {thisSuite: selectedSuites[i], suiteNo: i}) // routes to a call to runSuites
            var request = $.post("initiateMars", {thisSuite: suite, suiteNo: suitenumber}) // routes to a call to runSuites
            request.done(function(data, textStatus, jqXHR){
                waitForComplete();
                getMarsLog();
            })
            request.error(function(jqXHR, textStatus, errorThrown) {
                alert ("IR err: " + errorThrown);
            })
            alert ("done")
        }

    function getMarsLog()
    {
        var gmlRequest = $.get("getMarsLog"); // routes to a call to getMarsOutput
        gmlRequest.done(function(data, textStatus, jqXHR){
            console.log("Updating log")
            var logbox = document.getElementById("marsoutput");
            logbox.value = data;
            logbox.scrollTop = logbox.scrollHeight;
        })
        gmlRequest.error(function(jqXHR, textStatus, errorThrown) {
            alert ("GML err: " + errorThrown);
        })

    }

    function waitForComplete()
    {
        var wfcRequest = $.get("getMarsStatus"); // routes to a call to checkForMarsProcess
        wfcRequest.done(function(data, textStatus, jqXHR){
            if (data == "") {
                setTimeout(function(){
                    alert("No data found")
                    enableButton();
                    updateLogAndWait(0);}, 1000);
            }
            else{
                setTimeout(function(){
                alert("Data found")
                disableButton("RUNNING");
                updateLogAndWait(1);}, 1000);
            }
        })
        wfcRequest.error(function(jqXHR, textStatus, errorThrown) {
        })
        alert ("exiting WFC")
    }

    function updateLogAndWait(GMS)
    {
        if (GMS == 1)
        {
            console.log("Update and Wait")
            getMarsLog();
            waitForComplete()
        }
    }
(Note that functions such as disableButton etc not quoted here to keep it simple!)

Very simply - the call to waitForComplete in proecssThisSuite is executing synchronously - I need it to be asynchronous... processThisSuite will itself be called a number of times for a number of suites - which will be processed on the back end... And the back end processing of the suites does NOT support concurrent suite processing - so I need to ensure I only process one at a time...

Can someone please give an idiot proof guide (I'll let you guess who the idiot in question is!!!) as to how to (I believe using callbacks) make the call to WaitForComplete asynchronous - ie, call it, and wait for it to exit before continuing?

Thanks!