var xmlHttp;
function showUser()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request");
return
}
var uni = document.getElementById("uniqueid").value;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET","request.php?uniqueid="+ uni,true);
xmlHttp.send(null);
}function stateChanged()
{
if (xmlHttp.readyState == 4 )
{
if (xmlHttp.status==200)
{
var xmlDoc = xmlHttp.responseXML.documentElement;
var a = document.getElementById("barName");
var b = document.getElementById("bossName");
var c = document.getElementById("cellPhone");
// var d = document.getElementById("beginTM");
// var e = document.getElementById("endTM");
var f = document.getElementById("barAddress");
a.value =xmlDoc.getElementsByTagName("barname")[0].childNodes[0].nodeValue;
b.value =xmlDoc.getElementsByTagName("bossname")[0].childNodes[0].nodeValue;
c.value =xmlDoc.getElementsByTagName("cellphone")[0].childNodes[0].nodeValue;
// d.value =xmlDoc.getElementsByTagName("begintm")[0].childNodes[0].nodeValue;
// e.value =xmlDoc.getElementsByTagName("endtm")[0].childNodes[0].nodeValue;
f.value =xmlDoc.getElementsByTagName("baraddress")[0].childNodes[0].nodeValue;
document.getElementById("beginTM").innerHTML = xmlDoc.getElementsByTagName("begintm")[0].childNodes[0].nodeValue;
document.getElementById("endTM").innerHTML = xmlDoc.getElementsByTagName("endtm")[0].childNodes[0].nodeValue;
}
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
这个代码为什么在FF下面是正常的、在IE7 和IE8下面都提示
a.value =xmlDoc.getElementsByTagName("barname")[0].childNodes[0].nodeValue;为NULL啊、晕翻来、
因为他们对 domxml 的处理方式是不同的
你打个断点,看看浏览器取出这个是什么
有的浏览器把空白符组成的空行也当作一个节点
建议你用循环语句判断tagName取child
require("db/mysql_connect.php");
header("content-Type:'text/xml' ");
$uni = $_GET['uniqueid'];
$sql = "select barname,bossname,cellPhone,barAddress,beginTM,endTM from memberinfo where uniqueid = '".$uni."'";
$result = mysql_query($sql,$conn);
while ($row = mysql_fetch_array($result))
{
print '<?xml version="1.0" encoding="ISO-8859-1" ?>'
.'<note>'
.'<barname>'.$row['barname'].'</barname>'
.'<bossname>'.$row['bossname'].'</bossname>'
.'<cellphone>'.$row['cellPhone'].'</cellphone>'
.'<baraddress>'.$row['barAddress'].'</baraddress>'
.'<begintm>'.$row['beginTM'].'</begintm>'
.'<endtm>'.$row['endTM'].'</endtm>'
.'</note>';
}
?>我的XML结构非常简单、