Forum Moderators: open

Message Too Old, No Replies

add data

         

MarrkoR

10:49 am on Aug 31, 2009 (gmt 0)

10+ Year Member



Hi, i use jquery and this function:
var news = setInterval(function()
{
$('#news).load(news2.php?id='+ Math.random());
}, 5000);

But this function re-enter div.
I want to add a div, that old data remains.

daveVk

1:04 pm on Aug 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Put the news div within a newContianer div ( not part of load ), change #news to #newContianer.

MarrkoR

3:17 pm on Aug 31, 2009 (gmt 0)

10+ Year Member



Yes, but when refresh script after 5s. all data delete

daveVk

12:00 am on Sep 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought you where replacing news article with another each 5 secs ? Please explain what you would like to happen and what currently happens in a bit more detail, I do not understand problem.

whoisgregg

7:28 pm on Sep 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to simply append the new items to the old items, don't use .load() on the jQuery AJAX object. Instead, use .get() and define a callback function that uses .append() to add the returned content to the #news div.

MarrkoR

10:45 am on Sep 6, 2009 (gmt 0)

10+ Year Member



With your help built this:

<script>
$(document).ready(function(){
var data_old = setInterval(function()
{
$.get("test.php", function(data){
$('#vai').append("News: " + data);
});

}, 1000);
});
</script>

Everything works perfectly, thanks ;)