Mysterio4
Mysterio4

Reputation: 331

Unable to update page with ajax

I want to update a page with set of html links from another page every 5 seconds, but its not working. it only updates the page if i refresh it manually on browser. Please I need help

HTML PAGE

<div id="sto"></div>


<script>
    function upd(){
        $('#sto').html('');
        $.ajax({
            url:base_url+'process/ajax/get3.php',
            cache: false,
            async: false,
            dataType: 'html',
            success: function(resp)
            {

                //$('#sto').html(resp);
                $('#sto').append(resp);

            }
        })
    }
  setInterval(upd(), 5000)
</script>


PHP (get3.php - links generated from db)

<ul class="chat-history" id="group_history_2">
    <li><span class="user">Test Patient</span><p>ddd</p><span class="time">04:10</span></li>
    <li><span class="user">Test Patient222</span><p>ddd</p><span class="time">04:10</span></li>
  <li><span class="user">Test Patient333</span><p>ddd</p><span class="time">04:10</span></li>
</ul>

Upvotes: 1

Views: 49

Answers (1)

Eddie
Eddie

Reputation: 26854

You should pass the callback function as parameter on setInterval

Like:

setInterval(upd, 5000);
upd(); /*Add this so that you will call the ajax immediately after loading and no need to wait for 5seconds*/

You should remove the () on your code.

Upvotes: 3

Related Questions