What''s wrong with this:
Ajax.Responders.register({
onCreate: function() { alert(''create''); },
onFailure: function() { alert(''fail''); },
onSuccess: function() { alert(''succeed''); }
});
Only the create method is getting called.
Thanks!
-Daniel
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Hmm, just noticed the docs don''t list onFailure or onSuccess as valid
Responder callbacks. So how does one create a global error catch for non-2xy
responses?
Thanks!
-----Original Message-----
From: Daniel Eben Elmore
[mailto:DanielElmore-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org]
Sent: Friday, February 23, 2007 2:37 AM
To:
''rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org''
Subject: Ajax.Responders basic help needed
What''s wrong with this:
Ajax.Responders.register({
onCreate: function() { alert(''create''); },
onFailure: function() { alert(''fail''); },
onSuccess: function() { alert(''succeed''); }
});
Only the create method is getting called.
Thanks!
-Daniel
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Hey Daniel, Daniel Eben Elmore a écrit :> Hmm, just noticed the docs don''t list onFailure or onSuccess as valid > Responder callbacks. So how does one create a global error catch for non-2xy > responses?Ajax.Responders.register({ onComplete: function(req) { // arg2 = transport, arg3 = json... if (req.success()) // onSuccess code, or "this.onSuccess();" ;-) else // onFailure code, or "this.onFailure();" ;-) } }); -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nothing is wrong with it. There must be a problem in your code somewhere
else, or possibly even a problem with XMLHttpRequest in your
environment. If you''re sure you are getting a response, and if your
browser isn''t throwing any errors, try registering an onException
handler. Firefox throws the most useful exceptions (complete stack
traces) but these are caught by prototype so you''ll never see them in
Firebug or any browser. In fact, here is the code I use boiled down to
what you might find useful. (note, #container is an element in my
page''s
layout so change it if you''d prefer it printed to a specific location)
It works in all browsers I''ve tested. If this doesn''t help,
post more
code or preferably a live demo page.
Colin
----------------------------
function getDebugDiv(){
var debug = $(''debug_messages'');
if(!debug){
var container = $(''container'') || document.body;
debug =
Builder.node(''div'',{id:''debug_messages'',className:''debug''});
new Insertion.Bottom(container,''<h1>Debug
Console:<small>''+
''<a href="javascript:;"
onclick="$(\''debug_messages\'').innerHTML=\''\'';">(clear)</a></small></h1>'');
container.appendChild(debug);
}
return debug;
}
function getRequestDetails(request){
var resText = request.transport.responseText.escapeHTML();
var jsonHeader =
request.transport.getResponseHeader(''X-JSON'');
var jsonText = (jsonHeader ? jsonHeader.escapeHTML():false);
var message ''Method:
''+request.method+''<br/>''+
''URL: ''+request.url+''<br/>''+
''Parameters:
''+$H(request.parameters).toQueryString()+''<br/>''+
''Response: ''+request.transport.status+''
''+request.transport.statusText+''<br/>''+
''X-JSON: ''+(jsonText ?
''<pre>''+"\n\n"+jsonText+"\n"+''</pre>'':'''')+''<br/>''+
''Response Text: ''+(resText ?
''<pre>''+"\n\n"+resText+"\n"+''</pre>'':'''')+''<br/>'';
return message;
}
function getExceptionDetails(ex){
var message
''<b>''+ex.name+'':</b><pre>''+ex.message+''</pre><br/>''+
(ex.fileName && ex.lineNumber ? ex.fileName+'' (line
<b>''+ex.lineNumber+''</b>)<br/><br/>'':'''')+
(ex.description ?
''Description:<pre>''+ex.description+''</pre><br/>'':'''')+
(ex.stack ? ''Stack trace:
<pre>''+ex.stack+''</pre><br/>'':'''')+
(ex.number ? ''Number:
''+ex.number+''<br/>'':'''')+
(ex[''opera#sourceloc''] ? ''Location:
<b>''+ex[''opera#sourceloc'']+''</b><br/>'':'''');
return message;
}
function printDebug(){
var debug = getDebugDiv();
new Insertion.Bottom(debug,''<hr/>'');
for(var i=0; i < arguments.length; i++){ new
Insertion.Bottom(debug,arguments[i].toString()); }
}
Ajax.Responders.register({
onException: function(request,ex){
if(_debug_enabled || confirm(''An error occured processing your
request. This is possibly a bug.\n\nClick OK to see the details.'')){
printDebug(''<hr/><b>Exception occured during
Ajax.Request:</b><br/>''+getRequestDetails(request)+''<br/><br/>''+getExceptionDetails(ex)+''<br/>'');
var debug = getDebugDiv();
if(debug){ debug.scrollTo(); }
}
}
});
Daniel Eben Elmore wrote:> What''s wrong with this:
>
> Ajax.Responders.register({
> onCreate: function() { alert(''create''); },
> onFailure: function() { alert(''fail''); },
> onSuccess: function() { alert(''succeed''); }
> });
>
> Only the create method is getting called.
>
>
> Thanks!
> -Daniel
>
>
> >
> .
>
>
--~--~---------~--~----~------------~-------~--~----~
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">
Lol, I should''ve checked my mail before responding..<br>
I had never tried onSuccess or onFailure, but for the record, on*** do
work, such as on401, etc... Any reason not to add responders for these
two callbacks?<br>
<br>
Colin<br>
<br>
Christophe Porteneuve wrote:
<blockquote
cite="mid:45DEB400.3050803-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org"
type="cite">
<pre wrap="">Hey Daniel,
Daniel Eben Elmore a écrit :
</pre>
<blockquote type="cite">
<pre wrap="">Hmm, just noticed the docs don''t list
onFailure or onSuccess as valid
Responder callbacks. So how does one create a global error catch for non-2xy
responses?
</pre>
</blockquote>
<pre wrap=""><!---->
Ajax.Responders.register({
onComplete: function(req) { // arg2 = transport, arg3 = json...
if (req.success())
// onSuccess code, or "this.onSuccess();" ;-)
else
// onFailure code, or "this.onFailure();" ;-)
}
});
</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>
Thanks guys, works great.> Any reason not to add responders for these two callbacks?The docs say onSuccess and onFailure are "skipped if a code-specific callback is defined". Whatever that means? :) Perhaps that has something to do with it... -Daniel -----Original Message----- From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Colin Mollenhour Sent: Friday, February 23, 2007 3:44 AM To: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails-spinoffs] Re: Ajax.Responders basic help needed Lol, I should''ve checked my mail before responding.. I had never tried onSuccess or onFailure, but for the record, on*** do work, such as on401, etc... Any reason not to add responders for these two callbacks? Colin Christophe Porteneuve wrote: Hey Daniel, Daniel Eben Elmore a écrit : Hmm, just noticed the docs don''t list onFailure or onSuccess as valid Responder callbacks. So how does one create a global error catch for non-2xy responses? Ajax.Responders.register({ onComplete: function(req) { // arg2 = transport, arg3 = json... if (req.success()) // onSuccess code, or "this.onSuccess();" ;-) else // onFailure code, or "this.onFailure();" ;-) } }); --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey, Daniel Eben Elmore a écrit :> The docs say onSuccess and onFailure are "skipped if a code-specific > callback is defined". Whatever that means? :) Perhaps that has something to > do with it...Say you defined on200: it will be called instead of onSuccess. Same for on404 instead of onFailure if you do get a 404-code response. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Colin, Colin Mollenhour a écrit :> Lol, I should''ve checked my mail before responding.. > I had never tried onSuccess or onFailure, but for the record, on*** do > work, such as on401, etc... Any reason not to add responders for these > two callbacks?Not that I know of. I don''t have a single minute these days to write a tested patch (the patch would be easy enough, but providing good unit tests would take a bit longer). Feel free, man! :-) -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---