<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: 302 code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 29 Aug 2008 00:23:35 GMT</pubDate>
    <description>DZone Snippets: 302 code</description>
    <item>
      <title>Performing a redirect with AJAX</title>
      <link>http://snippets.dzone.com/posts/show/1156</link>
      <description>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.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;% link_to_remote "Foo",&lt;br /&gt;                  :url =&gt; { :action =&gt; "foo" },&lt;br /&gt;                  302 =&gt; "document.location = request.getResponseHeader('location')" %&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Or, an example from the Typo source:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;%= form_remote_tag :url =&gt; {:action =&gt; "comment", :id =&gt; @article}, &lt;br /&gt;                    :update =&gt; {:success =&gt; 'commentList'},&lt;br /&gt;                    :loading =&gt; "loading()", &lt;br /&gt;                    :complete =&gt; "complete(request)",&lt;br /&gt;                    :failure =&gt; "failure(request)",&lt;br /&gt;                    :html =&gt; {:id=&gt;"commentform",:class=&gt;"commentform"},&lt;br /&gt;	            302 =&gt; "document.location=request.getResponseHeader('location')"%&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 14 Jan 2006 02:55:30 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1156</guid>
      <author>brianellin (Brian Ellin)</author>
    </item>
  </channel>
</rss>
