Can I do a redirect in an ajax request?


#1

I’ve got a form on my page, and when the user submits it, sometimes
I’d like to update an element on my page, and sometimes I’d like to
redirect the browser to another url entirely. However if I do
redirect_to, it just updates the element with the results of the
redirect. Is it possible to do what I want, or will I need to use RJS
to do this?

Pat


#2

you don’t have to use RJS, but RJS is probably the simplest way.

rjs ex:

page.redirect_to :controller => …, :action => …, …


#3

Yeah I did some googling, and found that I could put this in the
controller:

render :update do |page|
page.redirect_to home_url
end

However when I do that, the text “window.location.ref=…” shows up
on the page. I don’t want the user to see that…maybe I can have it
show a custom message when it performs the action instead or
something?

Pat


#4

Okay once I took the update out of the form_remote_tag call, and just
used page.replace_html inside my controller, everything works nicely
and doesn’t show the JS in the page anymore. Thanks Chris!

Pat