admin管理员组文章数量:1401849
example
<script type="text/javascript" src=".3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function () {
$('#div').load('another.page');
}, 1000);
</script>
i dont want 'another.page' to load i just want to refreh the the '#div' div is it possible if it is how
thank you
example
<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function () {
$('#div').load('another.page');
}, 1000);
</script>
i dont want 'another.page' to load i just want to refreh the the '#div' div is it possible if it is how
thank you
Share Improve this question asked Jul 2, 2013 at 6:43 AstroAstro 131 gold badge1 silver badge4 bronze badges 2- If you don't want to load something new into the DIV, what do you mean by refresh it? – Barmar Commented Jul 2, 2013 at 6:45
- If you don't load any content in the div from another page, everytime you modify it in the same view, it will refresh automatically (you don't need any function to do it). Could you explain us what are you trying to do with an example? – maqjav Commented Jul 2, 2013 at 6:47
3 Answers
Reset to default 2If I understand you correctly, your problem is to re-render the DIV
automatically. So there are a number of ways you can force an element
to re-render (without a reload) - the most effective one I found was to quickly switch the display
style of the element
in question.
That is:
Set the display
property to none
:
element.style.display = 'none';
and then return it to block
element.style.display = 'block';
Here is the working demo of your example in JSFiddle.
Note: It's pure JavaScript
.
Here is an example of how you can update the content of a div without reloading the page. It's a bit unclear what you want from your question so I hope this helps.
html
<div id="divID"></div>
javascript
var counter = 1;
var auto_refresh = setInterval(
function () {
var newcontent= 'Refresh nr:'+counter;
$('#divID').html(newcontent);
counter++;
}, 1000);
Live example here.
You can't load just a part of the page just like that. But you can load all the page and fetch just the part you want. eg:
$.get('anoter_page.html',function(data){
myDiv = $(data).find('#divID');
$('#divID').html(myDiv.html());
})
Example: JSFiddle
本文标签: javascriptAuto Refresh a div without loading from another pageStack Overflow
版权声明:本文标题:javascript - Auto Refresh a div without loading from another page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744312550a2600099.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论