larry*wei 2015-03-13 03:13 采纳率: 0%
浏览 37

使用jQuery的Rails轮询

I have an index page that lists all users and their statuses (available or unavailable), every user can change his/her status anytime. What I am trying to do is real-time polling to display the most up to date statuses. I have done the Jquery polling function and it works (tried it with a simple alert and it displays the alerts every 10 seconds). Now I don't know what to include in my index.js.erb file, that code that's supposed to refresh the div that includes the users and their statuses. I have this :

$("#users-container").replaceWith("<%= escape_javascript(render @users) %>")

To replace the old users and theirs statuses with the new newer ones, but this is not working, the page is not changing at all.

Any suggestions?

Here is my index.html.erb

<div id="users-container">
  <%= render @users %>

</div>

_user.html.erb

<p> 
    <%= name_with_status(user.full_name, user.status, user.id) %>
    </p>

Where name_with_status is just a helper that displays the name, status.

  • 写回答

1条回答 默认 最新

  • weixin_33691817 2015-03-13 03:29
    关注

    You might want to try using .html() instead of .replaceWith(). In your case, you want to replace the contents of #users-container, but not the entire element itself.

    So you can do something like this:

    $("#users-container").html("<%= escape_javascript(render @users) %>")
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器