onSuccess and onComplete Prototype callbacks

Hi everyone,

The onSuccess callback gets fired when HTTP status code is 200, and onComplete gets fired AFTER onSuccess/onFailure when the browser has finished handling the request, i.e. when the DOM is ready, right?
So my question is where to put code that MUST ONLY be executed if HTTP status code is 200 AND Ajax.Request was called with option ‘evalScripts: true’. The code in question is attaching JS events to DOM nodes that were added by some server generated JS (the response of the Ajax.Request, hence evalScripts: true). I’m using the wonderful moodom JS library for this, cheers you guys!. For these purposes, it seems as if onSuccess is called too early. It looks like the DOM is not ready at that time, and onComplete is the real place to put the code (it works when I put it in onComplete, whereas it doesn’t in onSuccess). I really like the onSuccess/onFailure callbacks, as they make my code easier to read compared to if(
xhr.status == 200) {} else{} clauses in onComplete, but the latter seems to be unavoidable in situations like described above.

So, what I really want to know is actually more a question of style :slight_smile: Where do you guys put your code in situations like these? In particular, do you use both places, i.e. DOMready independent code into onSuccess/onFailure and DOMready dependent code into proper if branches in onComplete ? Or do you just put all the code into proper onComplete if branches, leaving out onSuccess/onFailure callbacks entirely?

I would really appreciate reading how you guys tackled situations like these

cheers
Martin Gamsjaeger