ajax:success and ajax:complete callback doesn't work when using UJS in Rails

后端 未结 4 614
醉梦人生
醉梦人生 2021-01-13 15:43

I have a link that when i click on it will trigger an ajax call then replace this link by another link, says for example the original link is \"add friend\", when i click th

4条回答
  •  深忆病人
    2021-01-13 16:21

    Try this in your action.js.erb:

    setTimeout(function () {
      ("#link_for_friend").html("<%= escape_javascript(render('users/cancel_link')) %>")
    });
    

    This will put the html replacement to the next timer tick that happens after the ajax:* events being triggered.

提交回复
热议问题