Note that there are some explanatory texts on larger screens.

plurals
  1. POrails 3 - ajax form ajax:success event not being called
    primarykey
    data
    text
    <p>After much troubleshooting, I am not able to figure out why my form's ajax:success callback is not being called in rails 3.</p> <p><strong>Following is the code ultimately generated in my view:</strong></p> <p><strong>JS Code:</strong></p> <pre><code>$(function() { $("#myform").bind('ajax:success', function(data, status, xhr) { alert("form success"); console.log(data); console.log(status); }).bind('ajax:error', function(xhr, status, error) { console.log(error); console.log(status); }); }); </code></pre> <p><strong>Ajax Form:</strong></p> <pre><code>&lt;form accept-charset="UTF-8" action="/myc/mya" data-remote="true" id="myform" method="post"&gt; &lt;div style="margin:0;padding:0;display:inline"&gt;&lt;input name="utf8" type="hidden" value="&amp;#x2713;" /&gt;&lt;input name="authenticity_token" type="hidden" value="hZuhxwboQj2qo8MPIR8DWwYMqAC1V2yqG+DX9UnlIr0=" /&gt;&lt;/div&gt; &lt;input class="large" id="foo" name="foo" type="text" /&gt; &lt;input class="btn success" data-disable-with="Working..." name="commit" type="submit" /&gt; &lt;/form&gt; </code></pre> <p><strong>Following the logic that happens in the action which the form posts to:</strong></p> <pre><code> @foo = { :foo =&gt; "bar" } render(:json =&gt; @foo.to_json, :content_type =&gt; 'application/json', :layout =&gt; false) </code></pre> <p>I have Firebugged this entire request/response:</p> <pre><code>It says 200 OK. And the Response Headers are: Cache-Control max-age=0, private, must-revalidate Connection Keep-Alive Content-Length 13 Content-Type application/json; charset=utf-8 Date Mon, 23 Jan 2012 10:37:19 GMT Etag "9bb58f26192e4ba00f01e2e7b136bbd8" Server WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09) Set-Cookie _session_id=BAh7CkkiD3Nlc3Npb25faWQGOgZFRiIlMGIzZGRhZDQ2ZjNmYzUzOWJkMzBkZWMxZDBmMDgwODZJIhBfY3NyZl90b2tlbgY7AEZJIjFoWnVoeHdib1FqMnFvOE1QSVI4RFd3WU1xQUMxVjJ5cUcrRFg5VW5sSXIwPQY7AEZJIhJyZXF1ZXN0X3Rva2VuBjsARkkiMGlCVmFZYllrU2R1RHl2aVZ4ZGc3ZWxKdmVxZkdFa1VKYWVXaHU0eXBmR1kGOwBUSSIZcmVxdWVzdF90b2tlbl9zZWNyZXQGOwBGSSIwcFdGTUVTUGt6d2VSY1pzV2YxU3JLNmFJSEpCU3FGMDh2ZmZ2U0pFaVI4cwY7AFRJIhRjdXJyZW50X3VzZXJfaWQGOwBGSSIpZDZiZDdhMjYtNDRjNi0xMWUxLTkwMDItZmExMjJjNjJmZTFmBjsARg%3D%3D--78099c697506ede3c7e9a833efa1785c6f1b9a6e; path=/; HttpOnly X-Runtime 0.354051 X-Ua-Compatible IE=Edge </code></pre> <p>The response is, as expected:</p> <pre><code>{"foo":"bar"} </code></pre> <p>200 OK response should trigger 'ajax:success' in my JS... but this is not happening. Any thoughts? The error callback is not being hit either...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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