[英]ajax xmlhttp response is null - javascript
这是我的代码:
<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>
我得到:无法为此行调用null的方法'getElementsByTagName':
var response = xmlhttp.responseXML.getElementsByTagName(“ theComment”)[0] .text;
Servlet发送了响应,因为在调试器中它说已收到回复,但是无论如何,这是Servlet中的代码:
response.setContentType("text/xml");
try {
response.getWriter().println("<theComment>asasasaasa<br></theComment>");
} catch (IOException e) {
e.printStackTrace();
}
浏览器是chrome。 谁能告诉我xmlhttp.responseXML为什么为空?
<br>
在xml中无效,请<theComment>asasasaasa<br/></theComment>
尝试<theComment>asasasaasa<br/></theComment>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.