Forum: Ruby on Rails Ajax callback to javascript array ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
251d4d717aa8e68b072d97d2d3309528?d=identicon&s=25 nano . (Guest)
on 2006-03-28 20:28
I have some javascript,

<script>
var arrCustomers;

function setCustomers(arr)
{
   arrCustomers= arr;
   // arrCustomers holds now array of customers
}
</script>


... and Rails controller,

class CustomersController < ApplicationController
    def list
        @customers = Customer.find_all
    end
end


... and Ajaxed link to get the customers,

<%= link_to_remote "Get customers",
    :url=>{
    :controller=>"customers",
    :action=>"list",
    :complete=>"setCustomers( 'what should i put here ????' )"
%>

I want to populate the javascript array with the response of the Ajax
call to my CustomersController. The javasript callback function
'setCustomers' gets called but I do not know how to pass customers as a
parameter?

Can you help me?
16bea4737847792ab0908d14743d4e1e?d=identicon&s=25 Scott (Guest)
on 2006-03-28 21:31
nano,
This is just one way.  Use the XMLHTTP object and write the return to
the arrCustomers variable.


Scott.
nano . wrote:
> I have some javascript,
>
> <script>
> var arrCustomers;
>
> function setCustomers(arr)
> {
>    arrCustomers= arr;
>    // arrCustomers holds now array of customers
> }
> </script>
>
>
> ... and Rails controller,
>
> class CustomersController < ApplicationController
>     def list
>         @customers = Customer.find_all
>     end
> end
>
>
> ... and Ajaxed link to get the customers,
>
> <%= link_to_remote "Get customers",
>     :url=>{
>     :controller=>"customers",
>     :action=>"list",
>     :complete=>"setCustomers( 'what should i put here ????' )"
> %>
>
> I want to populate the javascript array with the response of the Ajax
> call to my CustomersController. The javasript callback function
> 'setCustomers' gets called but I do not know how to pass customers as a
> parameter?
>
> Can you help me?
This topic is locked and can not be replied to.