一下,果不其然,在ff里面要使用textContent方法,且一定要遵从w3c标准使用getElementById获取div,不能图省事直接写id,在IE里面行的通,在火狐和其他浏览器就不
<!DOCTY
PE ht
ML P
ubLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.
org/TR/xhtml1/DTD/xhtml1
-strict.dtd">
<html>
<head>
<t
ITle>Ajax的第一个经典例子Hello World</title>
<script type="text/javascript">
VAR XMlHtt
p; function createXMLHtt
PRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function startRequest(){
createXMLHttpRequest();
try{
xmlHttp.onready
statechange = handleStateChange;
xmlHttp.open("GET", "data.xml", true);
xmlHttp.send(null);
}catch(exception){
alert("您要访问的资
源不存在!");
}
}
function handleStateChange(){
if(xmlHttp.readyState
== 4){
if (xmlHttp.status == 200 || xmlHttp.status == 0){
// 取得XML的DOM对象
var xmlDOM = xmlHttp.responseXML;
// 取得
XML文档的根
var root = xmlDOM.documentElement;
try
{
// 取得<info>结果
var info = root.
getelementsbytagname('info');
// 取字符串
var str_data = info[0].
FirstChild.data;
//
改变div的内容,调用changeText函数,注意IE和FF是不一样的
changeText(info[0].firstChild.data,'showText');
//innerHTML是一样的
document.getElementById("showTextHTML").innerHTML = '<
strong>' + info[0].firstChild.data + '</strong>';
}catch(exception)
{
}
}
}
}
function changeText(str,element){ //兼容IE和FF的
if(navigator.appN
ame.indexOf("E
xplorer") > -1){
document.getElementById(element).innerText = str;
} else{
document.getElementById(element).textContent = str;
}
}
</script>
</head>
<body>
<div>
<input type="button" value="return ajax responseXML's value"
onclick="startRequest();" />
</div>
<div id="showText"></div>
<div id="showTextHTML"></div>
</body>
</html>