ajax获取返回值问题
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>hello</TITLE>
</head>
<script type="text/javascript">
function getHttpObject(){
try{ return new XMLHttpRequest();}catch(e){}
try{ return new ActiveXObject('Msxml2.XMLHTTP.6.0');}catch(e){}
try{ return new ActiveXObject('Msxml2.XMLHTTP.4.0');}catch(e){}
try{ return new ActiveXObject('Msxml2.XMLHTTP.3.0');}catch(e){}
try{ return new ActiveXObject('Msxml2.XMLHTTP');}catch(e){}
try{ return new ActiveXObject('MSXML3.XMLHTTP');}catch(e){}
try{ return new ActiveXObject('MSXML.XMLHTTP');}catch(e){}
try{ return new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
try{ return new ActiveXObject('MSXML2.ServerXMLHTTP');}catch(e){}
return null;
}
function getContent(){
var request =getHttpObject();
//request.setRequestHeader('Content-Type', 'application/xml');
request.open("get","http://192.168.156.43/cgi-bin/get_dir",true);
request.setRequestHeader('Content-Type', 'application/xml');
//request.setContentType("application/xml");
if(request) {
request.onreadystatechange = function(){
if(request.readyState == 4){
var para = document.createElement('div');
var txt = document.createTextNode(request.responsexml);
para.appendChild(txt);
document.getElementById('list').appendChild(para);
}
};
//response.setContentType( "text/html;charset=gb2312 ")
request.ContentType=("application/xml;charset=UTF-8");
request.setRequestHeader('Content-Type', 'application/xml');
request.send(null);
}else {
alert('Sorry, your browser doesn\'t support XMLHttpRequest');
}
}
//addLoadEvent(getNewContent);
getContent();
</script>
</head>
<div id="list"></div>
通过抓包发现返回了数据包,但是无法获取~显示appendChild值为空~为什么,速度求解
------解决方案--------------------
var para = document.createElement('div');
document.getElementById('list').appendChild(para);
var txt = document.createTextNode(request.responsexml);
para.appendChild(txt);
试试,话说txt 是html标签吗?