在我的应用程序中,如果这是正确的词,我想附加或预先附加,这是对已显示的人员帖子列表的 ajax 请求的结果。我的意思是当用户点击帖子并触发 ajax 请求时,结果应该被推送到 div 中现有帖子列表的顶部。我想到的一种方法是在用户发布内容以获取按时间戳排序的新帖子列表后触发第二个 ajax 请求,这样帖子将自动出现在顶部,但这似乎是通过不必要的调用来惩罚数据库。
请建议最好和有效的方法。请不要为此建议 jquery,我想在原始 javascript 中执行此操作,稍后当我没有任何方法可以实现我想要实现时,我将使用 jquery。
我的 JavaScript 代码:
function postAjaxFade(){
t = document.getElementById("post").value;
// other element values like timestamp etc...
params = "post="+t+"&fl="+f;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
// what do i add here to append the value to top of this div below..
document.getElementById("postContainer").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","search.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(params);
}