Below is the code snippet:
<script type="text/javascript">
var xmlhttp;
$(document).ready(function (){
xmlhttp=new XMLHttpRequest();
});
function SubmitCommentAJAX(i){alert();
alert(i.parentNode.getElementsByClassName("commentsScroll")[0].innerHTML);
var thecomment=i.parentNode.getElementsByClassName("styled")[0].innerHTML;
var commentBox=i.parentNode.getElementsByClassName("commentsScroll")[0];
var request="http://localhost:8080/ituned.com/index?Event=Comment&PostTitle=<%=p.getTitle()%>&PostOwner=<%=p.getUsername_of_Owner()%>&comment="+thecomment;
xmlhttp.open("POST",request,true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var response=xmlhttp.responseXML.getElementsByTagName("theComment")[0].text;
commentBox.insertBefore(response, commentBox.firstChild);
}
};
}
</script>
An issue is encountered with the line that reads:
var response=xmlhttp.responseXML.getElementsByTagName("theComment")[0].text;
The servlet successfully sent back a response as confirmed in the debugger. Here's an excerpt of the servlet code:
response.setContentType("text/xml");
try {
response.getWriter().println("<theComment>asasasaasa<br></theComment>");
} catch (IOException e) {
e.printStackTrace();
}
The browser being used is Chrome. Need help understanding why xmlhttp.responseXML comes out as null.