Note that there are some explanatory texts on larger screens.

plurals
  1. PORails UJS link_to :remote does AJAX GET and normal <a href> GET
    text
    copied!<p><strong>EDIT:</strong></p> <p>In addition to the helpful comments below, two excellent articles by Steve Schwartz explain everything clearly: </p> <ul> <li><a href="http://www.alfajango.com/blog/rails-3-remote-links-and-forms/" rel="nofollow noreferrer">http://www.alfajango.com/blog/rails-3-remote-links-and-forms/</a></li> <li><a href="http://www.alfajango.com/blog/rails-3-remote-links-and-forms-data-type-with-jquery/" rel="nofollow noreferrer">http://www.alfajango.com/blog/rails-3-remote-links-and-forms-data-type-with-jquery/</a></li> </ul> <p>Rails 3.2.2 / jquery-rails 2.0.1 <em>(uses jquery 1.7.1)</em></p> <p>I have link which sends an AJAX request to add additional file upload fields to a form. <strong>Everything page-related works correctly</strong> - the new form field HTML fragment is retrieved from the server and appended to a div inside the form.</p> <p>However,</p> <p>The server receives two GET requests. One is the AJAX request ; the other appears to be the "normal" anchor element GET. I expected the "normal" GET would be stopped by Rails UJS.</p> <p>Am I supposed to disable the normal link action myself? Can someone please explain what I have misunderstood, and what I should be doing instead [to prevent the second request]?</p> <p>I've seen this question: <a href="https://stackoverflow.com/questions/4231885/rails-3-ujs-controller-gets-called-twice-by-link-to-remote">Rails 3 UJS - controller gets called twice by link_to :remote</a>. Accordingly, I tried changing the asset pipeline compilation <code>config.assets.debug = false</code>, but it had no effect. Moreover, this is not a double-AJAX GET request, so I think it's a different issue.</p> <p>Thanks for any help!</p> <p><strong>Server log snippet:</strong></p> <pre><code>Started GET "/files/new?asset_number=2" for 127.0.0.1 at 2012-03-23 15:23:27 +0100 Started GET "/files/new" for 127.0.0.1 at 2012-03-23 15:23:27 +0100 </code></pre> <p><strong>Browser HTML:</strong></p> <pre><code>&lt;a href="/files/new" data-remote="true" id="add_another_file" position="after" update="files"&gt;Add another file&lt;/a&gt; </code></pre> <p><strong>View:</strong></p> <pre><code>&lt;%= link_to 'Add another file', new_file_path, :remote =&gt; true, :update =&gt; 'files', :position =&gt; 'after', :id =&gt; 'add_another_file' %&gt; </code></pre> <p><strong>Controller's coffeescript:</strong></p> <pre><code>$( -&gt; $('a#add_another_file').click( -&gt; url = '/files/new?asset_number=' + $('#files input').length $.get(url, ((data) -&gt; $('#files').append(data)), 'html'))) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload