gal*_*gal 5 html javascript ajax jquery ruby-on-rails
我看过这篇关于这个问题的帖子: 每隔x秒自动刷新一个Html表
现在,我正在使用rails,我想做同样的事情,但我想告诉rails我想要一个远程页面,我不希望它加载整个页面.我想要的只是模拟:remote =>使用ajax的真实动作.我已经尝试了常规的ajax,rails会加载整个页面,而不仅仅是我想要的相关内容.
我该怎么做 ?
你的代码应该是这样的:
Your controller
def your_action
# your code goes here
end
Run Code Online (Sandbox Code Playgroud)
(your_action.js.erb)
$("#div_id").html("<%= escape_javascript reder :partial => "your_partial_for_table" %>")
Run Code Online (Sandbox Code Playgroud)
your_action.html.erb
<div id="div_id">
<%= render :partial => "your_partial_for_table" %>
</div>
Run Code Online (Sandbox Code Playgroud)
_your_partial_for_table.html.erb
#your table goes here
<script>
$(function() {
$(document).ready(function() {
setInterval(function() {
jQuery.ajax({
url: "<path to your_action>",
type: "GET",
dataType: "script"
});
}, 30000); // In every 30 seconds
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2348 次 |
最近记录: |