In php you could have a script: <?php
if (...) { // everything went fine, this will be sent to the onSuccess handler echo "the results"; } else { // there were some errors, this will be cought by prototype's onFailure handler header("HTTP/1.1 500 Internal Server Error"); } ?> See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for a list of available error codes. Prototype will set a response as "success" if the status code is between 200 and 300. Another solution: <?php // errors if (...) echo "0"; else echo "your results here"; ?> and just use the onSuccess handler, like new Ajax.Request(url, { onSuccess: function(r) { if (r.responseText == "0") return alert("error"); alert("success"); Element.update("mydiv", t.responseText); } }) Martin On 6/28/06, Il Neofita <[EMAIL PROTECTED]> wrote:
The problem is that I cannot understand how I can pass it and how I can catch it. I understand that for you it is so obvious. Can you give me an example? Please. See you On 6/28/06, Martinez, Andrew <[EMAIL PROTECTED]> wrote: > > > > > > How your back end reports the failure is up to you. You can pass back nothing, a 0, a 1, words, etc. Its your business logic at that point and completely arbitrary. > > > > > -Andrew Martinez > > > > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Il Neofita > > Sent: Wednesday, June 28, 2006 12:42 PM > To: rails-spinoffs@lists.rubyonrails.org > > Subject: Re: [Rails-spinoffs] Ajax.Updater > > > > > > > > I cannot understand something > > with declaring this object new Ajax.Request I will request the page /my/url > however, on the server side, how should look the files? I canno tunderstand how can I give a positive o negative feedback > > Thank you and sorry for these basic question > > > > On 6/28/06, Martin Ström <[EMAIL PROTECTED] > wrote: > > > Something like this should do it: > > new Ajax.Request("/my/url", { > asynchronous: true, > onSuccess: function(r) { > $("myDiv").innerHTML = "updated! new contents " + r.responseText; > }, > onFailure: function(r) { > alert("failed!") > } > }) > > > See the docs ( http://wiki.script.aculo.us/scriptaculous/show/Ajax.Request ) for more info > > Ciao > > Martin > > > > On 6/28/06, Il Neofita <[EMAIL PROTECTED]> wrote: > > > Hi Andrew, > I am not so good in Java, can you send me a basic example. > > Thank you > > > > On 6/28/06, Martinez, Andrew < [EMAIL PROTECTED]> wrote: > > > Don't use Ajax.updater. Use the regular Ajax object and then pass in your own onSuccess function handler/function pointer/functor. The handler/pointer/functor will receive the response test in a HTTP request object and you can evaluate it there. > > > > -Andrew Martinez > > > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Il Neofita > Sent: Wednesday, June 28, 2006 10:49 AM > To: rails-spinoffs@lists.rubyonrails.org > Subject: [Rails-spinoffs] Ajax.Updater > > > > Hi, > someone can help me, I am ot able to find the way how to user Ajax.updater to test if the request give some positive or negative result. > I am able only to return the result inside a div. > An example is appreciated. > > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > > > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs