# AJAX redirect, with absolute URL, corrupts the URL

**URL:** <https://www.ruby-forum.com/t/ajax-redirect-with-absolute-url-corrupts-the-url/108792>\
**Category:** Rails\
**Created:** [July 7, 2007, 2:57am UTC](https://www.ruby-forum.com/t/ajax-redirect-with-absolute-url-corrupts-the-url/108792 "2007-07-07T02:57:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [July 7, 2007, 2:57am UTC](https://www.ruby-forum.com/t/ajax-redirect-with-absolute-url-corrupts-the-url/108792/1 "2007-07-07T02:57:57Z")

</div>

I’m trying to redirect the browser to a URL outside of my domain on  
some AJAX calls.  
I do:

page.redirect\_to(some\_url)

It works fine with internal URLs, when I supply the :action  
and :controller, but absolute URLs fail. Rails insists on applying  
HTML encoding to the URL, thus replacing the & signs between arguments  
to &

- Same thing happens if I do the redirect from the .rjs template or  
from the controller.

Do I need to do something else to get this working?

Thanks,  
Amir

---

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [July 7, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/ajax-redirect-with-absolute-url-corrupts-the-url/108792/2 "2007-07-07T13:45:34Z")

</div>

Thanks Phlip,

That works great.

Amir

---

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [July 7, 2007, 4:52am UTC](https://www.ruby-forum.com/t/ajax-redirect-with-absolute-url-corrupts-the-url/108792/3 "2007-07-07T04:52:04Z")

</div>

helzer wrote:

> page.redirect\_to(some\_url)
> 
> It works fine with internal URLs, when I supply the :action  
> and :controller, but absolute URLs fail. Rails insists on applying  
> HTML encoding to the URL, thus replacing the & signs between arguments  
> to &

That might be an insect. Try more raw JavaScript:

page \<\< “window.location.href = ‘#{my\_uri}’;”

–  
Phlip  
[Test Driven Ajax (on Rails) [Book]](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax
