Hi and thanks!

I tried out what you mentioned and it works like a charm. Agh, so
stressful trying to figure this stuff out.

Thanks again.

On Oct 2, 11:18 am, bluezehn <[EMAIL PROTECTED]> wrote:
> So what you want to do is bind the onSuccess callback to the class in
> which this Ajax.Request is created. Theoretically this would go
> something like this:
>
> new Ajax.Request('./map/map.php?'+values,
>
> >                         {
> >                                 method:'get',
> >                                 onSuccess: function(transport)
> >                                 {
> >                                         this.response = 
> > transport.responseText || "no response text";
>
> >                                 }.bind(this),
> >                                 onFailure: function(){
> >                                         //
> >                                 }
> >                         }
> >                 alert(this.response);
>
> But I think you might be missing a key characteristic of Ajax Requests
> here. They are asynchronous - that means they're done in parallel. So
> your code executes like this:
>
> Send Ajax Request
> Well, I don't particularly want to wait around for the server to
> respond so I'm going to do something else
> Try to alert(this.response) - ouch, it didn't have anything in.
> I've got nothing to do now, tralalala...
> Oh that ajax request has finished! And it was succesful...
> Off to the onSuccess callback then. Set response, and...
> I've got absolutely nothing to do!
>
> The advantage of this is that you can have lots of them going on at
> the same time, in parallel. But you can't make assumptions that if you
> create requests in the order 1,2,3 they'll finish in that order - that
> depends on how the server handles them. Response 3 may be cached and
> come back straight away, for example.
>
> So your code should be something like this:
> someFunctionOnClass: function()
> {
>   new Ajax.Request('./map/map.php?'+values,
>                          {
>                                  method:'get',
>                                  onSuccess: function(transport)
>                                  {
>                                          this.response =
> transport.responseText || "no response text";
>                                          this.alertFunction();
>
>                                  }.bind(this),
>                                  onFailure: function(){
>                                          //
>                                  }
>                          }},
>
> alertFunction: function() { alert(this.response); }
>
> On Oct 2, 4:37 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > Hello all,
>
> > I seem to be going in circles with something I would have to assume
> > would be simple. Im trying to return a value from the onSuccess
> > handler but it will not keep the value.
>
> >                 new Ajax.Request('./map/map.php?'+values,
> >                         {
> >                                 method:'get',
> >                                 onSuccess: function(transport)
> >                                 {
> >                                         var response = 
> > transport.responseText || "no response text";
>
> >                                 },
> >                                 onFailure: function(){
> >                                         //
> >                                 }
> >                         });
> >                 alert(response);
>
> > Obviously this does not work. How can I access the variable outside of
> > the onSuccess event? Or, how could I access an object within the
> > onSuccess handler from outside of this scope?
>
> > I realize I can access and change global variables, but I am trying to
> > keep everything within my class which is what is causing me such
> > problems. I have tried using Bind, Call, and Apply but I don't think I
> > am using them right...
>
> > Any help would be very much appreciated.
>
> > Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to