hi guys, i have the following code: new Ajax.Request(window.location.href, { method: ''post'', parameters: params, requestHeaders: {Accept: ''application/json''}, onSuccess: function(transport) { if (!transport.responseText.startsWith(''root'')) { //CALL ON FAILURE WITH TRANSPORT AS ARG } if (func) func(transport.responseText.evalJSON(true).root); }, onFailure: function(trans) { alert("Erroro on callback:\n\n" + trans.responseText.stripTags()); } }); i wonder if its possible to call the onFailure-"method" within the onSucces (see the commented line within the onSuccess method). i tried this.onFailure(transport) onFailure(transport) nothing works. thanks for your help... cheers mcihal --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
michal wrote:> i wonder if its possible to call the onFailure-"method" within the > onSucces (see the commented line within the onSuccess method). i tried > > this.onFailure(transport) > onFailure(transport)Why not use a real function? function my_failure(transport) { ... } new Ajax.Request(window.location.href, { method : ''post'', parameters : params, requestHeaders : {Accept: ''application/json''}, onSuccess : function(transport) { if (!transport.responseText.startsWith(''root'')) my_failure(transport); }, onFailure : my_failure }); -- Michael Peters Developer Plus Three, LP --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
thanks thats a good idea and it works fine! however, i am wondering if i would be able to invoke the onFailure directly... On 5 Apr., 16:58, Michael Peters <mpet...-aUYv5hkjw45l57MIdRCFDg@public.gmane.org> wrote:> michal wrote: > > i wonder if its possible to call the onFailure-"method" within the > > onSucces (see the commented line within the onSuccess method). i tried > > > this.onFailure(transport) > > onFailure(transport) > > Why not use a real function? > > function my_failure(transport) { > ... > > } > > new Ajax.Request(window.location.href, { > method : ''post'', > parameters : params, > requestHeaders : {Accept: ''application/json''}, > onSuccess : function(transport) { > if (!transport.responseText.startsWith(''root'')) > my_failure(transport); > }, > onFailure : my_failure > > }); > > -- > Michael Peters > Developer > Plus Three, LP--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> There appears to be no reference back to Prototype''s Ajax object, and even setting new properties in the XHR object is forbidden in IE as Tobie (I think) discovered when we tried to add a responseJSON property. There is a patch for wrapping the XHR object, which could contain a reference back to the Ajax object, but I don''t know if it already does or what the status is on that. For now you''ll have to declare the function elsewhere and reference it with a closure like Michael suggested or hack the Prototype source to pass an extra argument, but I strongly recommend against that.<br> <br> Colin<br> <br> michal wrote: <blockquote cite="mid:1175851316.260892.69430-/7j0VgYmVpuxqywCgw793mB/v6IoIuQBVpNB7YpNyf8@public.gmane.org" type="cite"> <pre wrap="">thanks thats a good idea and it works fine! however, i am wondering if i would be able to invoke the onFailure directly... On 5 Apr., 16:58, Michael Peters <a class="moz-txt-link-rfc2396E" href="mailto:mpet...-aUYv5hkjw45l57MIdRCFDg@public.gmane.org"><mpet...-aUYv5hkjw45l57MIdRCFDg@public.gmane.org></a> wrote: </pre> <blockquote type="cite"> <pre wrap="">michal wrote: </pre> <blockquote type="cite"> <pre wrap="">i wonder if its possible to call the onFailure-"method" within the onSucces (see the commented line within the onSuccess method). i tried </pre> </blockquote> <blockquote type="cite"> <pre wrap="">this.onFailure(transport) onFailure(transport) </pre> </blockquote> <pre wrap="">Why not use a real function? function my_failure(transport) { ... } new Ajax.Request(window.location.href, { method : ''post'', parameters : params, requestHeaders : {Accept: ''application/json''}, onSuccess : function(transport) { if (!transport.responseText.startsWith(''root'')) my_failure(transport); }, onFailure : my_failure }); -- Michael Peters Developer Plus Three, LP </pre> </blockquote> <pre wrap=""><!----> </pre> </blockquote> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. <br> To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>
i see.. thanks for your reply .. i was just wondering and i am happy with the solution ;) On Apr 6, 1:08 pm, Colin Mollenhour <eliteii...-NPSFNn/7+NYVo650/ln6uw@public.gmane.org> wrote:> There appears to be no reference back to Prototype''s Ajax object, and even setting new properties in the XHR object is forbidden in IE as Tobie (I think) discovered when we tried to add a responseJSON property. There is a patch for wrapping the XHR object, which could contain a reference back to the Ajax object, but I don''t know if it already does or what the status is on that. For now you''ll have to declare the function elsewhere and reference it with a closure like Michael suggested or hack the Prototype source to pass an extra argument, but I strongly recommend against that. > Colin > michal wrote:thanks thats a good idea and it works fine! however, i am wondering if i would be able to invoke the onFailure directly... On 5 Apr., 16:58, Michael Peters<mpet...-aUYv5hkjw45l57MIdRCFDg@public.gmane.org>wrote:michal wrote:i wonder if its possible to call the onFailure-"method" within the onSucces (see the commented line within the onSuccess method). i triedthis.onFailure(transport) onFailure(transport)Why not use a real function? function my_failure(transport) { ... } new Ajax.Request(window.location.href, { method : ''post'', parameters : params, requestHeaders : {Accept: ''application/json''}, onSuccess : function(transport) { if (!transport.responseText.startsWith(''root'')) my_failure(transport); }, onFailure : my_failure }); -- Michael Peters Developer Plus Three, LP--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---