Hi,
I have successfully used dojo.connect() to call a custom Javascript method (in global scope) when the onDownloadEnd event fires on a TitlePane I have.
alert('here');
}
dojo.addOnLoad(function() {
var mySC = new dijit.layout.LayoutContainer( {title:"Source Container"}, dojo.byId("sourceContainer"));
var res_1 = new dijit.TitlePane({id: 'res_1', widgetId: 'res_1', style: 'padding-bottom: 15px;', title:'My Source', href:'/ts2/query/?sourceID=1&searchID=48'});
dojo.connect(res_1, 'onDownloadEnd', 'sourceXMLHandler');
mySC.addChild(res_1);
mySC.startup();
});
The above code snippet in essence is what's going on. My sourceXMLHandler simply has an alert right now, simply serving the purpose of letting me know that the method is actually getting called.
Note that I am using the 'href' attribute of the TitlePane, meaning that when the TitlePane is initialized, dojo makes an XHR to the location specified (/ts2/query, with some parameters), and XML is returned by that service.
According to the dojo documentation, the onDownloadEnd event fires after the response is received from the XHR, but before the setContent() method of the TitlePane is called to actually plop the response content into the widget.
My question is: inside the sourceXMLHandler method, how do I reference the XML that was returned? I will want to iterate over it and transform it into formatted DHTML.
Any help is much appreciated. Thanks!

More from the doc page...
"When you connect a function to a DOM event with dojo.connect, dojo passes your function a normalized event object. This means that, regardless of the client's browser, you can count on a set of standard attributes about the event and a set of methods to manipulate the event."
If that was the case, why is it that the debug yields "undefined"?
function sourceXMLHandler(event) {
console.debug(event);
}
dojo.connect(res_1, 'onDownloadEnd', 'sourceXMLHandler')
Again, I'm trying to manipulate content returned by the XHR returned from fetching the endpoint of an 'href' attribute of a TitlePane, before setContent() is called to place the content into the pane, namely to transform XML into HTML...
It seems the documentation for the eventing system is not accurately reflecting reality. Am I missing something?
Non-DOM events...
Ok, I see the distinction now. An event object is only passed on DOM events, explaining why I can't see it in debugging.
So, that begs the question - how can I manipulate the response of the href from the TitlePane? Is it even possible?
Update: Looks like this is not possible at this point
So it doesn't look like what I wanted to do is possible. Here's a transcript from the IRC channel. (My apologies to the mods if this isn't good etiquette.)
voltHeir Hello Dojo World! Looking for help intercepting data received from the XHR request issued by setting the 'href' attribute of a titlePane. I have successfully hooked into the onDownloadEnd event, but cannot find the response anywhere. Anyone care to help? http://dojotoolkit.org/forum/dijit-dijit-0-9/dijit-support/question-abou...
sfoster voltHeir: you might need to do the xhrGet yourself, and use the setContent method to push the new content back into the titlepane
voltHeir sfoster: thanks. that's what I was hoping not to hear. why is that?
voltHeir and to follow up: if that is the route i take, does dojo provide a mechanism for transforming an XML response into DHTML? (sorry for the noobish question...)
sfoster voltHeir: I dont know for a fact that you cant hook into the receiving of the data, sec...
voltHeir sfoster: sure thing. appreciate the help
sfoster voltHeir: are you doing setHref? or just giving the widget a href attribute?
voltHeir using the attribute on the initial payload, then using setHref to retrieve the "next page" (think a search UI...)
sfoster and you want to intercept the data coming back before it gets inserted?
voltHeir yes, namely to transform an XML response into DHTML before it gets setContent()ed
sfoster what you do mean DHTML?
voltHeir i mean HTML
sfoster so your server sends back xml, and you need to generate some html from it?
voltHeir exactly, yes
sfoster hrm. I think you may need to override setContent. Back in the day you could have done connectBefore
voltHeir does overriding setContent imply extending titlePane?
sfoster basically yes.
voltHeir ugh :)
sfoster well turning xml into html is not something the widget can reasonably be expected to do for you!
voltHeir i don't expect the widget to do it
voltHeir i expect an event object to be passed along with dojo.connect for non-DOM events, i suppose
voltHeir i've connected onDownloadEnd to a global function i've written, but no arguments get passed to that function via connect
sfoster no, its called without arguments.
voltHeir i'm sorry?
voltHeir i can see that
sfoster you can see for yourself in ContentPane.js,
sfoster I mean, no you are right.
voltHeir heh ok :)
voltHeir if i do the same thing for onClick, it works beautfiully, and the documentation reflects that
voltHeir it's too bad there's no way to pass an Event object along when connecting to a non-DOM event...
sfoster it might be nice if the downloadExternalContent exposed the Deferred object or something.
voltHeir oh well
sfoster I mean, voltHeir has a point - there's isnt really a good hook to pre-process the content before it gets slopped in.
voltHeir i will just parameterize my service to return HTML for my "native" app and XML for the API...less than ideal, but it will do
voltHeir thanks again, sfoster.
Alternatively, I can invoke xhrGet's in the initial payload (as opposed to titlePanes), then pre-process the response and plop them into titlePanes. But I think I will go with the parameterization I mentioned above.
Hope this helps someone in the future...