location.reload加载多次..点击时只需重新加载一次

时间:2015-01-08 04:40:58

标签: javascript jquery ajax

根据客户要求,我需要重新加载特定的div容器区域。是否可以在没有ajax的情况下刷新div容器?

相反,我尝试使用以下代码刷新页面,

 $('li.status-item a').click(function() {
    window.location.href=window.location.href;
});

$('li.status-item a').click(function() {
    location.reload();
});

这两个代码在我的本地环境中运行良好。当我在CMS环境中实现它时,在点击链接后每秒自动刷新页面。不知道为什么它会自动加载。需要一些专业知识才能解决问题。

请查看此链接以获取屏幕截图

http://teshdigitalgroup.com/team/reload.JPG

HTML代码:

<ul>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('single')">
        <img srcset="images/icons/single.png" alt="">
        <p>Single</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('attached')">
        <img srcset="images/icons/attached.png" alt="">
        <p>Attached</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('family')">
        <img srcset="images/icons/family.png" alt="">
        <p>Young family</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('retire')">
        <img srcset="images/icons/retire.png" alt="">
        <p>Going to retire</p>
    </a>
</li>
</ul>

由于

2 个答案:

答案 0 :(得分:0)

试试这个..

   <ul>
<li class="status-item">
    <a href="javascript:;" id="single" data-ng-click="setProfileStatus('single')">
        <img srcset="images/icons/single.png" alt="">
        <p>Single</p>
    </a>
</li>
<li class="status-item">
    <a href="javascript:;" id="attached" data-ng-click="setProfileStatus('attached')">
        <img srcset="images/icons/attached.png" alt="">
        <p>Attached</p>
    </a>
</li>
<li class="status-item">
    <a href="javascript:;" id="family" data-ng-click="setProfileStatus('family')">
        <img srcset="images/icons/family.png" alt="">
        <p>Young family</p>
    </a>
</li>
<li class="status-item">
    <a href="javascript:" id="retire"  data-ng-click="setProfileStatus('retire')">
        <img srcset="images/icons/retire.png" alt="">
        <p>Going to retire</p>
    </a>
</li>
</ul>
   <script>
$("li.status-item a").click(function() {
var url=document.URL;
var res = url.split("?");
var id=$(this).attr("id");
    if (window.location.href.indexOf(id)==-1) {
         window.location.href=res[0]+'?'+id;

    }

});
</script>

答案 1 :(得分:0)

请你在我的JSfiddle中复制你的问题。我尝试了你的代码它每次点击只重新加载一次。您的代码已在以下链接中更新

http://jsfiddle.net/ilaiya/72c5bvdy/1/

代码:

$('li.status-item a').click(function() {
    alert('Reload');
    location.reload();
});

<ul>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('single')">
        <img srcset="images/icons/single.png" alt="">
        <p>Single</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('attached')">
        <img srcset="images/icons/attached.png" alt="">
        <p>Attached</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('family')">
        <img srcset="images/icons/family.png" alt="">
        <p>Young family</p>
    </a>
</li>
<li class="status-item">
    <a href="#" data-ng-click="setProfileStatus('retire')">
        <img srcset="" alt="">
        <p>Going to retire</p>
    </a>
</li>
</ul>