I attempted to use this code snippet :
var xhttp = new XMLHttpRequest();
function activateComment(commentID, linkID)
{
var data = "id="+encodeURIComponent(commentID);
var endpoint = 'comments_handler.php';
xhttp.open("POST", endpoint, true);
xhttp.onreadystatechange = handleResponse(linkID);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.setRequestHeader("Content-length", data.length);
xhttp.setRequestHeader("Connection", "close");
xhttp.send(data);
}
function handleResponse(linkID)
{
if(xhttp.readyState == 1)
{
document.getElementById("commentResult").innerHTML = 'loading ..';
}
else if(xhttp.readyState == 4)
{
var reply = xhttp.responseText;
document.getElementById("commentResult").innerHTML = reply;
}
}
Although the readyState == 1
condition successfully updates the content of the commentResult
element, there seems to be an issue when readyState == 4
as no content is displayed in the same element.
If anyone has insight into what might be causing this problem, please share. Thank you!