var xmlhttp = new XMLHttpRequest();
xmlhttp.open( 'POST ', '../servlet/ajaxServlet ', true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200){
alert(xmlhttp.responseXML.xml);
alert(new XMLSerializer().serializeToString(xmlhttp.responseXML.getElementsByTagName( "div ")[0]));
}
}
}
我修改服务器端送回来的xml字段(xmlhttp.responseXML.xml),
如果是 " <?xml version=\ "1.0\ " encoding=\ "UTF-8\ " ?> <html xmlns=\ "http://www.w3.org/1999/xhtml\ " version=\ "-//W3C//DTD HTML 4.01 Transitional//EN\ "> <body> <div> test </div> </body> </html> ";
就取不到值。
如果是 " <?xml version=\ "1.0\ " encoding=\ "UTF-8\ " ?> <html> <body> <div> test </div> </body> </html> ",就能alert出来。
和解?
怎么样才能把第一种情况的div值取出来?
------解决方案--------------------
var doc = xmlhttp.responseXML
doc.setProperty( "SelectionNamespaces ", "xmlns:x= 'http://www.w3.org/1999/xhtml ' ")
var node = doc.selectNodes( "//x:div ")[0]
alert(node.text)
也可以