如何在提交后阻止表单刷新页面

时间:2016-09-22 11:14:54

标签: php jquery html css ajax

我使用来自互联网的聊天脚本,非常简单而且非常有效但是当我按下提交按钮时它会刷新整个页面。我想刷新形式而不是整个页面,因为我使用tabs.I使用3制表符:工作区,聊天和新闻,当我点击聊天时,它会打开另一个Tabulator,当我点击提交时,它会刷新整个页面并从Workspace选项卡开始。

这是代码。



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>
&#13;
&#13;
&#13;

你可以帮助我,所以当用户按下提交时,只刷新这个div。

0 个答案:

没有答案
相关问题