我有3个标签只会更改帖子的顺序。标签内容正在使用javascript更改而不刷新页面,但现在我需要刷新它,因为我正在使用ajax发布帖子,我需要在另一个标签中更新该帖子。
我的html标签代码:
<div id="tabs-container" >
<ul class="nav nav-tabs">
<li class="active test" id="recent" title="Order recommendations by Votes"><a href="#tab-1" >Votes</a></li>
<li class="test" id="votes" title="Order recommendations by Recent"><a href="#tab-2">Recent</a></li>
<li class="test" id="oldest" title="Order recommendations by Oldest"><a href="#tab-3">Oldest</a></li>
</ul>
</div>
<div class="tab">
<div id="tab-1" class="tab-content">
<p><%= render partial: 'improvement_actions/improvement_action', collection: @performance_indicator.improvement_actions.order(cached_votes_score: :desc), locals: { tab: "votes" } %></p>
</div>
<div id="tab-2" class="tab-content">
<p><%= render partial: 'improvement_actions/improvement_action', collection: @performance_indicator.improvement_actions.order("created_at DESC"), :locals => { tab: "recent" } %></p>
</div>
<div id="tab-3" class="tab-content">
<p><%= render partial: 'improvement_actions/improvement_action', collection: @performance_indicator.improvement_actions.order("created_at ASC") , :locals => { tab: "oldest" } %></p>
</div>
</div>
这是我的js代码:
$(document).ready(function() {
$(".nav-tabs a").click(function(event) {
event.preventDefault();
$(this).parent().addClass("active");
$(this).parent().siblings().removeClass("active");
var tab = $(this).attr("href");
$(".tab-content").not(tab).css("display", "none");
$(tab).fadeIn();
});
});
我试过了:
var url = window.location;
window.location = url;
或:
location.reload();
但是效果不好因为它出现了帖子然后刷新页面,而且它也慢了