Is it possible to refresh partial frequently using Ajax?

前端 未结 3 1013
旧时难觅i
旧时难觅i 2020-12-01 08:27

In background, I want it to reload and shows the number how many unread messages are there.
I want that without refreshing page. I mean using ajax.

If I had t

3条回答
  •  暖寄归人
    2020-12-01 09:01

    FYI, refresh_part.js.erb would look like this:

    $("#part").html("<%= escape_javascript(render 'partial', data: @data) %>");
    

    instead of:

    $('#part').html("#{escape_javascript(render 'partial', data: @data)}");
    

    also, we can use the alias of "escape_javascript" to simplify this:

    $("#part").html("<%= j(render 'partial', data: @data) %>");
    

提交回复
热议问题