I use this code to refresh a div with the id="my"
:
<script type="text/javascript">
function recp() {
setInterval(function()
{
$("#my").load(location.href+ ' #my');
});
}
</script>
<div id="my"><?php echo date('a:i:s'); ?></div>
It works, but it generates this code:
<div id="my"><div id="my">pm:25:40</div></div>
How can refresh the div without generating a double div?
In other words how can refresh only this div:
<div id="my"><?php echo date('a:i:s'); ?></div>
add another div as a container and load content to it, like that.
<script type="text/javascript">
function recp() {
setInterval(function()
{
$("#result").load(location.href+ ' #my');
});
}
</script>
<div id="result">
<div id="my"><?php echo date('a:i:s'); ?></div>
</div>
Alter your code to use $.get()
instead of .load()
<script type="text/javascript">
function recp() {
setInterval(function() {
$.get(location.href, function(data){
$('#my').empty().append( $(data).find('#my').children() );
});
});
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With