これが私のコードです:
<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>
次の行で :Cannot call method 'getElementsByTagName' of null を取得します:
var response=xmlhttp.responseXML.getElementsByTagName("コメント")[0].text;
デバッガーでは応答を受信したと表示されるため、サーブレットは応答を送信しましたが、サーブレット内のコードは次のとおりです。
response.setContentType("text/xml");
try {
response.getWriter().println("<theComment>asasasaasa<br></theComment>");
} catch (IOException e) {
e.printStackTrace();
}
ブラウザはクロームです。xmlhttp.responseXML が nul である理由を誰か教えてもらえますか??