Deferred is happening asynchronous, so you can't think in incremental,
imperative code. You pseuodosample could f.ex. be written as:

<div id="out"></div>
<input type="button" id="btn" value="clickme" />
<script>
var onClick = function() {
        var onCheck = function(data) {
                getElement("out").innerHTML = data;
        }
        var d = loadJSONDoc("/foo/bar");
        d.addCallback(onCheck);
}
connect(getElement("btn"), "onclick", onClick);
</script>

When The button is clicked, onClick is called. This calls loadJSONDoc.
When loadJSONDoc is done, it calls local function onCheck.
Hope this helps.

On 11/13/06, .M. <[EMAIL PROTECTED]> wrote:
>
> Hi there. I'm having trouble using Deferreds to do some basic AJAX
> calls. Something fundamental I'm not clear on yet.
>
> With re. to the following fragment
>
> Q) Where does the callback function return its variable to? How can you
> access it?
>
> Q) How can you check whether the callback has happened yet from another
> function (e.g. business() below so that you don't continue until it's
> taken  place?
>
> function check() {
>     d.loadJSON("/foo/bar");
>     d.addCallback(resultsItem);
> }
>
> function resultsItem() {
>    // record the results of the checking someplace - where?
>
>    checks = something;
>    return checks;
> }
>
> function business() {
>    check();
>
>    // don't go forward until results of check are handled
>
>    do something reliant on check() being accurate;
> }
>
> Any help would be great!
>
> Thanks
>   .M.
>
>
> >
>


-- 
troels

--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to