Hi.

I've been diving into the Ajax code in the core.

Some observations.

1 - Registered Ajax.Responders for onSuccess/onFailure are not called
(http://dev.rubyonrails.org/ticket/9643).

2 - Registered Ajax.Responders for onXYZ are not called.

I've got a way to deal with this, but I'm not sure if there is a "better" way.

Basically, the Ajax.Responders.dispatch() method needs to return
true/false if there was a dispatch.

==========code==========
  dispatch: function(callback, request, transport, json) {
    var b_Return = false;
    this.each(function(responder) {
      if (Object.isFunction(responder[callback])) {
        try {
          responder[callback].apply(responder, [request, transport, json]);
          b_Return = true;
        } catch (e) { }
      }
    });
  return b_Return;
  }
==========code==========

So, now in Ajax.Request.prototype.respondToReadyState() method
includes this mod (extends the patch I've supplied) ...

==========code==========
if(!Ajax.Responders.dispatch('on' + response.status, this, response,
response.headerJSON)) {
  Ajax.Responders.dispatch('on' + (this.success() ? 'Success' :
'Failure'), this, response, response.headerJSON);
}
==========code==========

This matches the behaviour of the non responder callbacks (the ones
supplied to the request in the options collection).

3 - Exceptions.

It seems that the parameters to the onException callback only includes
the Ajax.Request object. If you are trying to examine the data
returned (say a JSON object supplied in a header as X-JSON, which is
visible in the Ajax.Response), you can't.

Every response has a reference to the request, but not the other way around.

==========code==========
Ajax.Response.prototype = {
  initialize: function(request){
    this.request = request;
==========code==========

Is there any complication in adding ...

==========code==========
this.request.response = this;
==========code==========

This attaches the response to the request which is then passed to the
exception handler and now you can get to the json in the header. Phew!



I hope this is understandable.

Regards,

Richard Quadling.



-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

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

Reply via email to