当我点击我的按钮时,它可以刷新div一次,但是如果我再点击它就不会刷新div。
我必须点击F5重新加载页面
问题:我多次尝试点击我的按钮怎么能让它能够刷新#rep div?
success: function(response){
if (response.success == true) {
//window.location.reload();
$('#rep').load(window.location.href + ' #rep');
}
}
完整脚本
<script type="text/javascript">
$(document).ready(function() {
$('#vote-up-icon').on('click', function(e) {
e.preventDefault();
$.ajax({
url: "<?php echo base_url('thread/voteup/');?><?php echo $thread_id;?>",
type: 'post',
dataType: 'json',
data: {
voteup: $(this).parent().find('#vote_up').val()
},
success: function(response){
if (response.success == true) {
//window.location.reload();
$('#rep').load(window.location.href + ' #rep');
}
}
});
});
});
</script>
HTML
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-12 text-center">
<div id="rep">
<div class="form-group">
<i class="fa fa-chevron-up fa-2x" id="vote-up-icon" aria-hidden="true" style="cursor: pointer;"></i>
<input type="hidden" name="vote_up" id="vote_up" value="1" />
</div>
<div class="form-group" class="votes">
<?php echo $thread_votes;?>
</div>
<div class="form-group">
<i class="fa fa-chevron-down fa-2x" id="vote-down-icon" aria-hidden="true" style="cursor: pointer;"></i>
<input type="hidden" name="vote_down" id="vote_down" value="0" />
</div>
</div>
</div>
答案 0 :(得分:1)
感谢A. Wolff和其他所有人
<script type="text/javascript">
$(document).ready(function() {
$('#rep').on('click', '#vote-up-icon', function(e) {
e.preventDefault();
$.ajax({
url: "<?php echo base_url('thread/voteup/');?><?php echo $thread_id;?>",
type: 'post',
dataType: 'json',
data: {
voteup: $(this).parent().find('#vote_up').val()
},
success: function(response){
if (response.success == true) {
$('#rep').load(window.location.href + ' #rep');
}
}
});
});
});
</script>