PDA

View Full Version : UpdateManager Failure Event



Domitian
2 Feb 2007, 7:10 PM
So I've been working for a week on this stuff and I finally ran into the issue of scripts being loaded into innerHTML. I've been avoiding this issue but I finally can't. After writing a singleton to load all my asynchronous calls for my system I found out that I should be using the UpdateManager to load pages with scripts that were placed into a div after the page was already rendered. So I'm ripping out the singleton I wrote and trying to replace it with the UpdateManager, which is going alright. The only problem I have has to do with my error handler. In my original system, I was forcing the backend to fail when a user incorrectly submits a form to the system. In this particular case, I'd have my backend code return a customized HTTPResponse of 402. In my original callback I'd handle this accordingly by bringing up an error dialog in my handleFailure:function(o) and printing out the ResponseText. I'd like to translate this over to the UpdateManager.

I already tried to implement the callback specified in the API, but I needed a handle to the responseText which I don't have in the UpdateManager implementation (or so I believe). I noticed that there was an failure event object, but I was unable to find any examples on how to use it. My guess was that I'd have to override the existing one and implement my own. Is this correct? Even better, is there a better way to implement the scenario I just described.

aconran
2 Feb 2007, 9:28 PM
To attach a function to the onfailure event you can use the following:
yourUpdateMgr.on('failure', this.myFunction.createDelegate(this));

This will call this.myFunction in the event of a failure. myFunction's definition can be:
myFunction(YAHOO.ext.Element el, Object oResponseObject)

This way you can handle the error and will be able to use the responseText to parse out a custom message and take appropriate action.

Domitian
2 Feb 2007, 10:01 PM
Thanks aconran, that's what I needed to understand.