tags:

views:

144

answers:

1

This may also be simple Javascript related but here is the link to IO just in case: YUI3 IO

I have a YUI instance created and am using the io function to retrieve data from the server.

YUI().use('event', 'node', 'io', function(Y) {

    Y.on('io:start', onstart, this, true);
    Y.on('io:success', changecontent, this);
    Y.on('io:end', onend, this, true);

// irrelevant code has been omitted

function loadpage(e) {
    var request = Y.io(uri+"/"+tgt);
}

});

Does this mean that if I, at any time, use Y.io on start/success/end it will call onstart/changecontent/end respectively?

I want to make multiple calls to the server but have different functions to handle the results from each call. How would I go about doing this?

Thank you.

A: 

Yes, the way you're doing it the events are global. However, you can pass a config option that only applies for a single XHR. It should be something like:

Y.io(uri + "/" + tgt, { 
                        "on": 
                            {
                              "start": onstart,
                              "complete": changecontent,
                              "end": onend
                            },
                        "context": this
                      });
Matthew Flaschen
If I place the events in the loadpage function will that remove them from their global status? what is an XHR?
XHR stands for XMLHttpRequest (http://en.wikipedia.org/wiki/Xmlhttprequest). And yes, if you put them solely in the direct call, they will not be active globally.
Matthew Flaschen
Thanks, is this functionality documented anywhere? It worked but I needed to remove "Dispatch" and change them to the correct function names. what is "Dispatch" for? I haven't been able to find this use in any of the YUI3 docs.
It's actually documented on the same page you linked to, particularly at http://developer.yahoo.com/yui/3/io/#configuration. Dispatch was just a object relied on by one of their examples. I left it in by mistake.
Matthew Flaschen
Oh I see now, thanks!