# Question about ajax/rjs and redirection

**URL:** <https://www.ruby-forum.com/t/question-about-ajax-rjs-and-redirection/55030>\
**Category:** Rails\
**Created:** [March 16, 2006, 1:41pm UTC](https://www.ruby-forum.com/t/question-about-ajax-rjs-and-redirection/55030 "2006-03-16T13:41:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 16, 2006, 1:41pm UTC](https://www.ruby-forum.com/t/question-about-ajax-rjs-and-redirection/55030/1 "2006-03-16T13:41:01Z")

</div>

i don’t even know if this is possible, so I’ll just ask.

say I have a remote form. the form data gets submitted to the backend  
via  
AJAX. if there is a validation error in the form, i handle that on the  
AJAX  
side. however, if the form validates, I’d like to redirect the browser  
to a  
different page. Will a redirect\_to work with an AJAX call or do I have  
to  
handle that a special way?

ie

class AjaxController \< ApplicationController::Base

def do\_something  
#validate the form data  
redirect\_to :controller =\> “xyz”, :action =\> “abc” and return if  
data.validated?  
# otherwise, render the rjs template  
end  
end

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 16, 2006, 2:48pm UTC](https://www.ruby-forum.com/t/question-about-ajax-rjs-and-redirection/55030/2 "2006-03-16T14:48:36Z")

</div>

you need to check a result and if positive do a client-side redirect  
(javascript)

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 24, 2006, 2:08pm UTC](https://www.ruby-forum.com/t/question-about-ajax-rjs-and-redirection/55030/3 "2006-03-24T14:08:36Z")

</div>

you can do

def do\_something  
#validate form data  
render :update { |page| page.redirect\_to("/controller/action") } if  
data.validated?  
#otherwise render rjs template  
end
