我想更新我的页面详细信息而不刷新页面,我几乎完成了!
但我遇到的问题是,第二个div不会更新,有时会发生这种情况。所以,我感到很困惑。 updatediv()
功能有问题吗?
帮助或建议。谢谢。
JAVA SCRIPT
function updatediv(postid) {
//Change button to like or unlike
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("likebutton"+postid).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","likebutton.php?id="+postid,true);
xmlhttp.send();
//Count likes and update to #likestatus div
//My problems is HERE sometimes work sometimes doesn't work
var xmlhttp2=new XMLHttpRequest();
xmlhttp2.onreadystatechange=function() {
if (xmlhttp2.readyState==4 && xmlhttp2.status==200) {
document.getElementById("likestatus"+postid).innerHTML=xmlhttp2.responseText;
}
}
xmlhttp2.open("GET","likestatus.php?id="+postid,true);
xmlhttp2.send();
}
HTML
<a href="javascript:void(0)" id="likestatus<? echo $postid; ?>" onclick="updatediv(<? echo $postid; ?>)">Like</a>
<div id="likestatus<? echo $postid; ?>">0 like this</div>