If I give Ajax.Updater a first arg like{ success: ''replies'', failure: ''errors''}, how do I return an error from a php script so the message goes in ''errors'' rather than ''replies''? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
David Dashifen Kees
2007-Apr-04 13:00 UTC
Re: Ajax.Updater -- returning failure from a php script
Try making a header call in your PHP script that explicitly sets an HTTP error code. For example: header("HTTP/1.0 403 Forbidden"); Then, when the client sees that, it knows things have failed. I''ve used this trick when making sure that people are logged in and haven''t been timed out. -- Dash -- mikewilson wrote:> If I give Ajax.Updater a first arg like{ success: ''replies'', failure: > ''errors''}, how do I return an error from a php script so the message > goes in ''errors'' rather than ''replies''? > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 4 avr, 08:44, "mikewilson" <mikewilso...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> If I give Ajax.Updater a first arg like{ success: ''replies'', failure: > ''errors''}, how do I return an error from a php script so the message > goes in ''errors'' rather than ''replies''?The function doesn''t anticipate any response type from the server. You should read the API to know what onFailure and onError convers (and what are their role in the request). As long as success is executed, you should handle your server response from there. This is so, because return values and error handling should not be limited to a standard since there can be as many different implementations as there are types of responses. You may consider using a general purpose response handler for your requests if you plan on using the same implementation in your return value (which is a good idea by the way). For instance, try looking at Ajax.Responders to register a global callback function. In any case, if you only want to handle one kind of response the way you do, it is clear that onFailure, and onError are not appropriate to warn the user about that kind of failure, as they should be used only if there is a problem with the returned value itself (i.e. a malformed XML document for instance) or if the script/server is unavailable for the moment. If onSuccess is called, it means that the request has successfully been executed, regardless of if the script encountered an error or not. If you are using JSON, you may consider having a value ''errorCode'' and ''errorMsg'' (or similar) in your response. If errorCode == 0, then the request was successful. If you are using XML, you may consider using a tag such as <error> to enclose information about exceptions, etc. The benefit of having a general error handler is that errors may be catch and process in a cohesive way. Which means that if you change the way you want to handle errors, you will not find yourself refactoring all your code to compensate for the inconsistencies. If you are using XML, you may consider Rico (at http://www.openrico.org/) which allows you to register XML tags to elements (that will be automatically updated) or objects (that will be called with the node as parameter). [...] Good luck. -yanick --~--~---------~--~----~------------~-------~--~----~ 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 for both replies -- I have a much better understanding of what is going on now and can can the results I need. On Apr 4, 2:14 pm, "Yanick" <yanick.roc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 4 avr, 08:44, "mikewilson" <mikewilso...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > If I give Ajax.Updater a first arg like{ success: ''replies'', failure: > > ''errors''}, how do I return an error from a php script so the message > > goes in ''errors'' rather than ''replies''? > > The function doesn''t anticipate any response type from the server. You > should read the API to know what onFailure and onError convers (and > what are their role in the request). As long as success is executed, > you should handle your server response from there. This is so, because > return values and error handling should not be limited to a standard > since there can be as many different implementations as there are > types of responses. > > You may consider using a general purpose response handler for your > requests if you plan on using the same implementation in your return > value (which is a good idea by the way). For instance, try looking at > Ajax.Responders to register a global callback function. > > In any case, if you only want to handle one kind of response the way > you do, it is clear that onFailure, and onError are not appropriate to > warn the user about that kind of failure, as they should be used only > if there is a problem with the returned value itself (i.e. a malformed > XML document for instance) or if the script/server is unavailable for > the moment. If onSuccess is called, it means that the request has > successfully been executed, regardless of if the script encountered an > error or not. > > If you are using JSON, you may consider having a value ''errorCode'' and > ''errorMsg'' (or similar) in your response. If errorCode == 0, then the > request was successful. If you are using XML, you may consider using a > tag such as <error> to enclose information about exceptions, etc. > > The benefit of having a general error handler is that errors may be > catch and process in a cohesive way. Which means that if you change > the way you want to handle errors, you will not find yourself > refactoring all your code to compensate for the inconsistencies. > > If you are using XML, you may consider Rico (athttp://www.openrico.org/) > which allows you to register XML tags to elements (that will be > automatically updated) or objects (that will be called with the node > as parameter). [...] > > Good luck. > > -yanick--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---