Ajax.Request is doing an asynchronous call so the alert(rows) is run
before the ajax request finishes. You'll either want to make the Ajax
request synchronous or do all the logic that depends on the rows inside
of the onSuccess function.
Trevan
RobertG wrote:
> Hello,
>
> this must be something stupid but I can't figure out how to keep
> JSON data recevied from AJAX call after the request is finished, the
> array comes out always empty. I must be doing some dump perlish
> assumption or doing something stupid
>
> var rows = [];
> document.observe( "dom:loaded", function() {
> new Ajax.Request( '/ajaxrsp.html', { method: 'get', onSuccess:
> function( transport ) {
> rows = $A( transport.responseJSON );
> rows.each( function( row, i ) { alert( row + '/' + i ) } )
> }})
> alert( rows );
> }
>
> alert in the request body show the actual data but the second alert
> returns empty. Do I have to deep-clone it by hand or what? Please
> help. Thanks a lot.
>
> Robert G
> >
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---