Topic: ajax form. Pass params to external link

Hello,

I have a problem with ajax, I have in my view

<%= form_remote_tag :update => "result_div", :url => {:action => "foo"},:method => 'get' %>
<%= text_field_tag :bar %> <br/>
<%= end_form_tag %>

and in the controller i have


def foo
.....
redirect_to "http://www.barbaz.com/index?text=#{params[:bar]}"
end

I want the params to be passed on as arguments to a external site..

Any idea how this can be done?

The reason Im doing this is because I want to be able to have an ajax form which sends off its params to an external server using GET without the user having to goto the page, but instead simply uses an ajax form.

Re: ajax form. Pass params to external link

you must open the connection from your server to the external side, the client cannot open AJAX connections to sites other than the domain it has recieved the page where the AJAX call is made from. Thats a security limitation of JS.

You can however use Net:HTTP (part of Ruby core i think) or a similar liabrary to open the conection from the server, and e.g. Hpricot to parse the result, all on the server side, and then send the stuff you want back to the client with RJS.

Last edited by Duplex (2007-10-23 08:46:00)

Re: ajax form. Pass params to external link

That did the trick, thank you! smile