Never been to DZone Snippets before?

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

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

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')"%>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS