0

I'm using chat script from the internet,very simple and very effective but when I press submit button it refreshes the whole page.I want to refresh just form not the entire page because I use tabs.I use 3 Tabulators: Workspace , Chat, and News and when I click chat it opens another Tabulator and when I click submit it refresh the whole page and starts from Workspace tab.

Here is the code.

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','chat.php',true); 
    req.send();
}
setInterval(function(){ajax()},1000);
.chat_s {
    margin-top:20px;
    padding:20px;
    width:100%;
    height:200px;
    background-color: #f1f1f1;
    border-radius: 3px;
}
.chat_s textarea {
    width:400px;
    background-color:#f9f9f9;
    height:70px;
    border:none;
    resize: none;
    outline:none;
    font-size:13px;
    padding:20px;
}
.chat_s input[type=submit]{
    background-color:#e7544a;
    color:white;
    height:30px;
    width:100px;
    margin-top:40px;
    display:block;
}
                    <div class="chat_s">
                        <form id="chat_f" method="post" action="list.php">
                    <input type="hidden" name="name" value="<?php echo $user_name;?>"/> 
                    <input type="hidden" name="img" value="<?php echo $user_img;?>"/>
                    <input type="hidden" name="role" value="<?php echo $user_role;?>"/>
              <textarea name="msg" placeholder="Upisite Vasu poruku."></textarea>
              <input type="submit" name="send_msg" value="Posalji"/>
                            <br/>
                        </form>
                    </div>

Can you help me so when user press submits it refresh just this div.

Amar A.
  • 29
  • 7

0 Answers0