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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744312551a4568018.html
评论列表(0条)