日期:2014-05-16 浏览次数:20693 次
window.onload=function(){
//设置时间戳
var timestamp=0;
var request;
//更新内容
updateMsg();
//提交发布信息
$('aa').onclick=function(){
sendRequest();
}
//创建xmlHttpRequest对象函数
function create_request(){
if(window.ActiveXObject){
request=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
request=new XMLHttpRequest();
}else{
alert("你的浏览器不支持ajax功能!")
}
}
//回调函数
function back_do(){
if (request.readyState == 4 && request.status == 200) {
var get1=request.responseText;
var getsend=eval("("+get1+")");
$('body1').innerHTML= $('body1').innerHTML+getsend.sendtext;
timestamp=getsend.timestamp;
}
else if (request.status == 404) {
alert("Request URL does not exist");
}
}
//发送
function sendRequest(){
create_request();
var url="member/content_send.php";
var data="q_id="+$('qid').innerHTML+"&"+"saytext="+$('text1').value+"&"+"action=post";
request.open("POST",url,true);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.onreadystatechange=back_do;
request.send(data);
}
//从数据库更新信息
function updateMsg(){
create_request();
var url="member/content_send.php";
var data="q_id="+$('qid').innerHTML+"&"+"time="+timestamp+"&"+"action=update";
request.open("POST",url,true);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.onreadystatechange=back_do;
request.send(data);
setTimeout(updateMsg,3000);
}
//取id的值
function $(id){
return document.getElementById(id);
}
}
<div id='body1'>
</div>
<div id='footer'>
<form method="post" action="">
<input type="hidden" name="q_id" value="<?php echo $q_id;?>"/>
<textarea id='text1' name='saytext'>在此输入文本...</textarea>
<input type="submit" id='aa' value=''/>
</form>
</div>