When i use this
function getLogin() {
new Ajax.Updater("","index.php?m=login&c=getLogin",
{
method:''post'',
onSuccess: function(transport)
{
var response = transport.responseText
//alert("Success! \n\n" + response);
alert("A: "+response);
return response;
} ,
onFailure: function(){ showLoginerror(''Die Verbindung zum Server
wurde
unterbrochen!''); }
});
}
i want the return value but i think, the function ends befor e the
request is finishes. How can i get the return value ?!
____________
Virus checked by G DATA AntiVirusKit
Version: AVK 17.7607 from 11.09.2007
Virus news: www.antiviruslab.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
i believe you want to use Ajax.Request http://wiki.script.aculo.us/scriptaculous/show/Ajax.Request On 9/11/07, retacom-Mmb7MZpHnFY@public.gmane.org <retacom-Mmb7MZpHnFY@public.gmane.org> wrote:> > > When i use this > > function getLogin() { > new Ajax.Updater("","index.php?m=login&c=getLogin", > { > method:''post'', > onSuccess: function(transport) > { > var response = transport.responseText > //alert("Success! \n\n" + response); > alert("A: "+response); > return response; > > } , > onFailure: function(){ showLoginerror(''Die Verbindung zum > Server wurde > unterbrochen!''); } > }); > } > > > i want the return value but i think, the function ends befor e the > request is finishes. How can i get the return value ?! > > ____________ > Virus checked by G DATA AntiVirusKit > Version: AVK 17.7607 from 11.09.2007 > Virus news: www.antiviruslab.com > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hello, i change the function but its the same. i get the alert from the request afeter the return is finished :(> i believe you want to use Ajax.Request > > http://wiki.script.aculo.us/scriptaculous/show/Ajax.Request > >____________ Virus checked by G DATA AntiVirusKit Version: AVK 17.7614 from 11.09.2007 Virus news: www.antiviruslab.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello this is my code but when i alert the response after the return, i get ''undefined''> i believe you want to use Ajax.Request > > http://wiki.script.aculo.us/scriptaculous/show/Ajax.Request > > > On 9/11/07, *retacom-Mmb7MZpHnFY@public.gmane.org <mailto:retacom-Mmb7MZpHnFY@public.gmane.org>* <retacom-Mmb7MZpHnFY@public.gmane.org > <mailto:retacom-Mmb7MZpHnFY@public.gmane.org>> wrote: > > > When i use this > > function getLogin() { > new Ajax.Updater("","index.php?m=login&c=getLogin", > { > method:''post'', > onSuccess: function(transport) > { > var response = transport.responseText > //alert("Success! \n\n" + response); > alert("A: "+response); > return response; > > } , > onFailure: function(){ showLoginerror(''Die > Verbindung zum Server wurde > unterbrochen!''); } > }); > } > > > i want the return value but i think, the function ends befor e the > request is finishes. How can i get the return value ?! > > ____________ > Virus checked by G DATA AntiVirusKit > Version: AVK 17.7607 from 11.09.2007 > Virus news: www.antiviruslab.com <http://www.antiviruslab.com> > > > > > >____________ Virus checked by G DATA AntiVirusKit Version: AVK 17.7614 from 11.09.2007 Virus news: www.antiviruslab.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The problem is that Ajax is asyncrhonous. So when you fire the request
the Ajax.Request ends and the onFailure/onSuccess/onComplete method
gets "saved" to be called when the request finishes.
What you can do is use a global variable, like so:
Ajax.Request("index.php", {
parameters: { m: "login", c: "getLogin" },
onSuccess: function(transport) {
window.ajaxResult = transport;
},
onFailure: function(transport) {
window.ajaxResult = transport;
}
});
When the request ends you''ll have ajaxResult set.
However, I''d advise first reading about Ajax and understanding how it
works, as it''ll make this really easy to get :)
http://www.pragmaticprogrammer.com/title/ajax/
http://www.amazon.com/Ajax-Action-Dave-Crane/dp/1932394613
Best,
-Nicolas
On 9/11/07, retacom-Mmb7MZpHnFY@public.gmane.org
<retacom-Mmb7MZpHnFY@public.gmane.org> wrote:>
> Hello
>
> this is my code but when i alert the response after the return, i get
> ''undefined''
>
> > i believe you want to use Ajax.Request
> >
> > http://wiki.script.aculo.us/scriptaculous/show/Ajax.Request
> >
> >
> > On 9/11/07, *retacom-Mmb7MZpHnFY@public.gmane.org
<mailto:retacom-Mmb7MZpHnFY@public.gmane.org>*
<retacom-Mmb7MZpHnFY@public.gmane.org
> > <mailto:retacom-Mmb7MZpHnFY@public.gmane.org>> wrote:
> >
> >
> > When i use this
> >
> > function getLogin() {
> > new
Ajax.Updater("","index.php?m=login&c=getLogin",
> > {
> > method:''post'',
> > onSuccess: function(transport)
> > {
> > var response = transport.responseText
> > //alert("Success! \n\n" +
response);
> > alert("A: "+response);
> > return response;
> >
> > } ,
> > onFailure: function(){
showLoginerror(''Die
> > Verbindung zum Server wurde
> > unterbrochen!''); }
> > });
> > }
> >
> >
> > i want the return value but i think, the function ends befor e
the
> > request is finishes. How can i get the return value ?!
> >
> > ____________
> > Virus checked by G DATA AntiVirusKit
> > Version: AVK 17.7607 from 11.09.2007
> > Virus news: www.antiviruslab.com
<http://www.antiviruslab.com>
> >
> >
> >
> >
> > >
>
>
> ____________
> Virus checked by G DATA AntiVirusKit
> Version: AVK 17.7614 from 11.09.2007
> Virus news: www.antiviruslab.com
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---