mrk
mrk

Reputation: 99

How to refresh div in order to get newly incoming data from DB

I am using the jquery news ticker from (http://jquerynewsticker.com/) as my footer. The footer is only loaded once, hence if I get new data to my DB, the new data won't show.

I want that the news ticker div is refreshed by itself every x seconds, so if there is new data in my DB, that it will be shown.

the news ticker is currently:

<div class="footer" id="footerticker">
    <ul id="js-news" class="js-hidden">
    <c:forEach items="${handcarryTicker}" var="handcarry2">
        <li class="news-item">
            <td>LGP: ${handcarry2.item1}</td>
            <td>${handcarry2.item2}</td>
        </li>
    </c:forEach>
    </ul>
</div>

I found several solutions for refreshing a div, but unfortunately, they did not work for me. The footer is loaded and shown 3 seconds and then it disappears. How can I fix my code that it refreshes but not disappears?

My current script is:

<script>
    function refresh() {
        setInterval(() => {
            $('#footerticker').load(document.URL +  ' #footerticker')
        }, 3000);
    }
$(document).ready(refresh);
</script>

Upvotes: 0

Views: 47

Answers (1)

tverghis
tverghis

Reputation: 999

The first parameter to setInterval should be the function that you want to execute every 3000 milliseconds. In your example, update is not a defined function.

What you probably want is something like this:

<script>
    function refresh() {
        setInterval(() => {
            $('#footerticker').load(document.URL +  ' #footerticker')
        }, 3000);

    }
$(document).ready(refresh);
</script>

Upvotes: 1

Related Questions