info-p71QuHlbIm4TPDSnJhnt0wC/G2K4zDHf@public.gmane.org
2007-Feb-24 11:13 UTC
get return-value from ajax.request
Hi, first of all, as I''m new here I want to introduce mysqlf. My name is Felix, I''m from Hannover, germany and startet that Ajax thing with prototype about 2 month ago. Well, everything works OK, but now I habe a problem. I start a function, that calls another function, where I do an Ajax.Request. In the Ajax.Request I use the onComplete-Function to get the JSON- objectprovided by my php-script. Now I want one part of the JSON-object to be returned to the first function. Example: var function1 = function(vars) { var return = function2(vars); alert(return) // => undefined } var function2 = function(vars) { var opt = { // Use POST method: ''get'', // Send this lovely data parameters: vars, // Handle successful response onComplete: function(t,j) { var variable = j.Content; return variable; } } new Ajax.Request(''script.php'', opt); } I hope you understand what I mean. Thanx for help. Felix --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Felix, Well, this can''t be done by being asynchronous... Your function call chain requires synchronous processing, but by default, AJAX requests are, as the initial A implies, asynchronous: they''ll execute "in the background," while your function2 keeps going ahead. I advise you find another way to fetch this, because if you stick to your function model (requiring the function''s result is your AJAX returned value), you''ll need to make your AJAX request *synchronous*, which essentially means it will kinda freeze the window while it''s being processed. From an ergonomical standpoint, that can be very inconvenient. Still, you can do it by setting the asynchronous option to false. But beware: that''s like shooting yourself in the foot. You''d be better off devising another workflow for your code... -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: 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 -~----------~----~----~----~------~----~------~--~---
info-p71QuHlbIm4TPDSnJhnt0wC/G2K4zDHf@public.gmane.org
2007-Feb-26 11:02 UTC
Re: get return-value from ajax.request
Well, thanx for your answer. I thougt it would be that thing but wasn''t sure. Well, so I have to finde another workaround. Felix --~--~---------~--~----~------------~-------~--~----~ 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 2/26/07, info-p71QuHlbIm4TPDSnJhnt0wC/G2K4zDHf@public.gmane.org <info-p71QuHlbIm4TPDSnJhnt0wC/G2K4zDHf@public.gmane.org> wrote:> > Well, thanx for your answer. > > I thougt it would be that thing but wasn''t sure. > Well, so I have to finde another workaround. > > Felix >You can export your ''alert(return);'' in a dedicated function : var function3 = function(content) { alert(content); } which will be called by: ... onComplete: function(t,j) { var variable = j.Content; function3(variable); } ... Yours, Nicolas Terray --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
info-p71QuHlbIm4TPDSnJhnt0wC/G2K4zDHf@public.gmane.org
2007-Feb-28 14:26 UTC
Re: get return-value from ajax.request
Well actually it''s not an alert I want to make, that wouldn''t be a big problem :-) But I need the given back content to be placed in different containers on my page. So, that''s not the sollution I need. Thanx, Felix --~--~---------~--~----~------------~-------~--~----~ 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 2/28/07, info-p71QuHlbIm4TPDSnJhnt0wC/G2K4zDHf@public.gmane.org <info-p71QuHlbIm4TPDSnJhnt0wC/G2K4zDHf@public.gmane.org> wrote:> > Well actually it''s not an alert I want to make, that wouldn''t be a big > problem :-) But I need the given back content to be placed in > different containers on my page. >Then just replace the alert by the statements you need : var function3 = function(content) { $(''field'').value = content; new Insertion.Top(''div'', content); ... } Yours, Nicolas --~--~---------~--~----~------------~-------~--~----~ 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 Feb 28, 9:26 am, "i...-p71QuHlbIm4TPDSnJhnt0wC/G2K4zDHf@public.gmane.org" <i...-p71QuHlbIm4TPDSnJhnt0wC/G2K4zDHf@public.gmane.org> wrote:> Well actually it''s not an alert I want to make, that wouldn''t be a big > problem :-) But I need the given back content to be placed in > different containers on my page. >You should consider how Rico (http://openrico.org/) handles that kind of thing... Of course, this means having some understanding of XML, but the idea is that if you setup your client code right, it''s your server scripts that will decide what will be updated on the client, and what object should handle the request. The lib doesn''t code with a full documentation yet, but fairly enough for anyone to start basic examples and grow on it. 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 -~----------~----~----~----~------~----~------~--~---