ajax:成功回调在rails中不起作用

时间:2020-12-31 20:16:38

I have a small form on the page that looks like

我在页面上有一个小表单,看起来像

<div id="updater">
    <%= form_for current_user,:remote=>true do |f| %>
        please update your <%= f.label @field %>: 
        <%= f.text_field @field %>
        <%= f.submit %>
      <% end %>
 </div>

This triggers the Users#update which has respond_to format.js

这会触发具有respond_to format.js的Users#update

update.js.erb is

$("#updater").bind("ajax:success", function(xhr, data, status) {
    $("#updater").remove();
});

so the form will disappear once the the field has been updated

因此,一旦字段更新,表单将消失

I see that the JS is sent on the network tab on the chrome inspect thingy and the field does update in the DB. yet the #updater doesn't disappear, not if I add alert("updater"); I don't see the alert.

我看到JS是在chrome inspect thingy上的网络选项卡上发送的,并且该字段确实在DB中更新。然而#updater并没有消失,如果我添加警报(“更新程序”);我没有看到警报。

Am I not catching the ajax:success correctly?

我没有抓住ajax:成功吗?

1 个解决方案

#1


0  

I seem to have another js file that is working on #updater.. once I removed that it started working..

我似乎有另一个js文件正在#updater工作..一旦我删除它开始工作..

#1


0  

I seem to have another js file that is working on #updater.. once I removed that it started working..

我似乎有另一个js文件正在#updater工作..一旦我删除它开始工作..