0

i am trying to access the content in that particular id called chat_date on page load, but it is getting the entire webpage. below is the javascript code.

<script>
    function ajax(){

    var req = new XMLHttpRequest();

    req.onreadystatechange = function(){

    if(req.readyState == 4 && req.status == 200){

    document.getElementById('chat').innerHTML = req.responseText;
    } 
    }
    req.open('GET','task.php',true); 
    req.send();

    }
    setInterval(function(){ajax()},1000);
</script>

below is the other PHP page i want to get values from.

<?php 
include 'php_includes/db.php';

$query = "SELECT * FROM chat ORDER BY id DESC";
$run = $db_conx->query($query);
while($row = $run->fetch_array()) :
    ?><div class="chat chat-left"  id="chat_data">
         <div class="chat-avatar">
                                                        <a href="profile.html" class="avatar">
                                                            <img alt="" src="assets/img/profiles/avatar-02.jpg">
                                                        </a>
                                                    </div>
     <div class="chat-body">
                                                        <div class="chat-bubble">
                                                            <div class="chat-content">


              <span class="task-chat-user"><?php echo $row['name']; ?>
              </span> <span class="chat-time"><?php echo $row['date']; ?></span>

                                                                <p> <?php echo $row['msg']; ?></p>
                                                            </div>
                                                        </div>
                                                    </div>



        <?php endwhile;?>

0 Answers0