I just thought of a simple solution that would not require messing with
the transport object. I posted a comment on Tobie's ticket
(http://dev.rubyonrails.org/ticket/7295#comment:15) to the same effect,
but I'll post it here for others to see as well. Why not eval the X-JSON header, then, if Content-type is 'application/json', eval it as well and Object.extend the X-JSON eval'ed response! This is more similar to Tobie's original suggestion, only rather than replacing it you would extend it. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~--- |
- [Rails-spinoffs] Re: About X-JSON header and evil things.... Colin Mollenhour
- [Rails-spinoffs] Re: About X-JSON header and evil th... tobie
- [Rails-spinoffs] Re: About X-JSON header and evi... Colin Mollenhour
- [Rails-spinoffs] Re: About X-JSON header and... Colin Mollenhour
This solution has the following advantages:
So a response like:
---------------
X-JSON: ({status: "go"})
Content-type: application/json
({data: ['one','two','ten']})
----------------
Could be used like so:
----------------
Ajax.Responders.register({
onSuccess: function(xhr,json){
if(json.status && json.status != 'go'){ alert('Error!'); }
}
});
new Ajax.Request(page,{
onSuccess: function(xhr,json){
$('count').update($A(json.data).map(function(item){ return '<li>'+item.camelize()+'</li>'; }).join(''));
}
});
Thoughts? I personally prefer this over my original suggestion which was to add a new property to the transport, mainly for simplicity.
Colin