DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Performing A Redirect With AJAX
If a redirect is returned from the rails' form_remote_tag or link_to_remote methods, a message is displayed saying something like "You are being redirected", where "redirected" is a link the user must click. The code snippet below will actually redirect the user to the proper location, without them having to click the link. Code works for both form_remote_tag or link_to_remote methods.
<% link_to_remote "Foo",
:url => { :action => "foo" },
302 => "document.location = request.getResponseHeader('location')" %>
Or, an example from the Typo source:
<%= form_remote_tag :url => {:action => "comment", :id => @article},
:update => {:success => 'commentList'},
:loading => "loading()",
:complete => "complete(request)",
:failure => "failure(request)",
:html => {:id=>"commentform",:class=>"commentform"},
302 => "document.location=request.getResponseHeader('location')"%>






Comments
Snippets Manager replied on Tue, 2006/12/05 - 3:14pm