Ajax callback to javascript array?


#1

I have some javascript,

… 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?


#2

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,

… 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?