我正在尝试创建一个将最新帖子插入 div 的帖子按钮,而不清除里面的所有内容。我当前的代码插入了新的分隔符,但清除了其中的所有内容,所以我只得到了最后一篇文章。
有谁知道如何修理它?
谢谢
代码是:
var xmlHttp
function submitNews() {
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
alert ("Your browser does not support XMLHTTP!");
return;
}
var content = document.getElementById('newsfeed_box').value;
var uid = document.getElementById('pu_uid').innerHTML;
var url="ajax/submit_post.php";
url=url+"?post="+content+"&id="+uid;
url=url+"&validate="+Math.random();
xmlHttp.onreadystatechange=stateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChange() {
switch(xmlHttp.readyState) {
case 1:
document.getElementById('successs').innerHTML = "<img src=\"style/images/loader.gif\" />";
document.getElementById('successs').style.display = "block";
break;
case 2:
document.getElementById('successs').innerHTML = "<img src=\"style/images/loader.gif\" />";
document.getElementById('successs').style.display = "block";
break;
case 3:
document.getElementById('successs').innerHTML = "<img src=\"style/images/loader.gif\" />";
document.getElementById('successs').style.display = "block";
break;
case 4:
var newdiv = document.createElement('div');
newdiv.innerHTML = xmlHttp.responseText;
document.getElementById('successs').appendChild(newdiv);
break;
}
}
// creating the XMLHttpRequest
function GetXmlHttpObject() {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject) {
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}