# How to escape from AJAX URL

**URL:** <https://www.ruby-forum.com/t/how-to-escape-from-ajax-url/54076>\
**Category:** Rails\
**Created:** [February 22, 2006, 11:00am UTC](https://www.ruby-forum.com/t/how-to-escape-from-ajax-url/54076 "2006-02-22T11:00:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fishman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fishman2001](https://www.ruby-forum.com/u/fishman2001)\
**Post date:** [February 22, 2006, 11:00am UTC](https://www.ruby-forum.com/t/how-to-escape-from-ajax-url/54076/1 "2006-02-22T11:00:24Z")

</div>

This may be a bit difficult to explain, but here goes.

I’m developing a web site which has a nice AJAX part to it (thanks to  
rails). You just click on the link and it take you to the ajax part  
which is on a seperate page.

-The user then selects directories or files from via a multiple menu.

-When the user selects a directory (and hits the submit button) the menu  
is updated with the next directory selected.

-When the user selects a file (and hits the submit button) the  
application should go back to the previous page and display the file  
he/she selected.

OK this does work apart from the fact that after the file is selected  
and the page goes back, the URL is still displaying the AJAX enhanced  
page. I’d like it to display the URL of the page it went back to  
otherwise I know the user will start to question this.

does anyone know how to escape from that?

Cheers.

---

<div class="post-metadata">

**Author:** ![fishman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fishman2001](https://www.ruby-forum.com/u/fishman2001)\
**Post date:** [February 22, 2006, 3:45pm UTC](https://www.ruby-forum.com/t/how-to-escape-from-ajax-url/54076/2 "2006-02-22T15:45:59Z")

</div>

fish man wrote:

> This may be a bit difficult to explain, but here goes.
> 
> I’m developing a web site which has a nice AJAX part to it (thanks to  
> rails). You just click on the link and it take you to the ajax part  
> which is on a seperate page.
> 
> -The user then selects directories or files from via a multiple menu.
> 
> -When the user selects a directory (and hits the submit button) the menu  
> is updated with the next directory selected.
> 
> -When the user selects a file (and hits the submit button) the  
> application should go back to the previous page and display the file  
> he/she selected.
> 
> OK this does work apart from the fact that after the file is selected  
> and the page goes back, the URL is still displaying the AJAX enhanced  
> page. I’d like it to display the URL of the page it went back to  
> otherwise I know the user will start to question this.
> 
> does anyone know how to escape from that?
> 
> Cheers.

I think the last step you can use redirect the whole page to the one you  
want instead of using Ajax to update part of it.

-Tony

---

<div class="post-metadata">

**Author:** ![fishman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fishman2001](https://www.ruby-forum.com/u/fishman2001)\
**Post date:** [February 22, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/how-to-escape-from-ajax-url/54076/3 "2006-02-22T17:01:36Z")

</div>

yes I did try that, using redirect\_to :action =\> ‘blahblahblah’  
but the URL was still the Ajax page so if you hit refresh it goes back  
to the original ajax page. but if i hit the back button it gives me what  
I want.

Tony J. wrote:

> fish man wrote:
> 
> > This may be a bit difficult to explain, but here goes.
> > 
> > I’m developing a web site which has a nice AJAX part to it (thanks to  
> > rails). You just click on the link and it take you to the ajax part  
> > which is on a seperate page.
> > 
> > -The user then selects directories or files from via a multiple menu.
> > 
> > -When the user selects a directory (and hits the submit button) the menu  
> > is updated with the next directory selected.
> > 
> > -When the user selects a file (and hits the submit button) the  
> > application should go back to the previous page and display the file  
> > he/she selected.
> > 
> > OK this does work apart from the fact that after the file is selected  
> > and the page goes back, the URL is still displaying the AJAX enhanced  
> > page. I’d like it to display the URL of the page it went back to  
> > otherwise I know the user will start to question this.
> > 
> > does anyone know how to escape from that?
> > 
> > Cheers.
> 
> I think the last step you can use redirect the whole page to the one you  
> want instead of using Ajax to update part of it.
> 
> -Tony

---

<div class="post-metadata">

**Author:** ![fishman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fishman2001](https://www.ruby-forum.com/u/fishman2001)\
**Post date:** [February 22, 2006, 5:09pm UTC](https://www.ruby-forum.com/t/how-to-escape-from-ajax-url/54076/4 "2006-02-22T17:09:09Z")

</div>

use RJS templates… I had this “exact” problem, but RJS did the trick.  
within my “login.rjs” template that get’s invoked after my login  
process, it  
returns to the same page with an error message on error, or… if the  
login  
was successful, it needs to “redirect” to another controller… which is  
pretty much impossible to do otherwise. so, my “login.rjs” looks like:

if @logged\_in\_client  
page.replace\_html “message”, :partial =\> ‘shared/bad\_login’  
else  
page.redirect\_to “whatever you want here”  
end

i was scared to use edge rails at first, but now i swear by it 🙂
