下面的XML解析是一位大哥写给我的,但在我本机IE浏览器运行没效果,望各位大虾看看是什么问题
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function creatXHR(){
if (window.ActiveXObject) return new window.ActiveXObject('Microsoft.XMLDOM');
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
}
function getText(node){
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);
}
function done(xhr){
var text = getText(xhr.responseXML.getElementsByTagName('div')[0]);
document.getElementById("aa").innerHTML = text;
}
</script>
</head>
<body>
<div id="aa" onClick="a();" style="width:400px; height:400px; background-color:#0066FF;"></div>
<script type="text/javascript">
function a(){
var xhr = creatXHR();
xhr.open('GET', 'image-flow.xml?r='+ (new Date()).getTime(), false);
xhr.send(null);
try {
done(xhr);
} catch (e) {
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200) {
done(xhr);
}
}
}
}
</script>
</body>
</html>
<?xml version="1.0" encoding="utf-8"?>
<div>
<img src="boom.jpg"></img>
</div>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function creatXHR(){
if (window.ActiveXObject) return new window.ActiveXObject('Microsoft.XMLDOM');
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
}
function getText(node){
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);
}
function done(xhr){
var text = getText(xhr.responseXML.getElementsByTagName('div')[0]);
document.getElementById("aa").innerHTML = text;
}
</script>
</head>
<body>
<div id="aa" onClick="a();" style="width:400px; height:400px; background-color:#0066FF;"></div>
<script type="text/javascript">
function a(){
var xhr = creatXHR();
xhr.open('GET', 'image-flow.xml?r='+ (new Date()).getTime(), false);
xhr.send(null);
try {
done(xhr);
} catch (e) {
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200) {
done(xhr);
}
}
}
}
</script>
</body>
</html>
<?xml version="1.0" encoding="utf-8"?>
<div>
<img src="boom.jpg"></img>
</div>
解决方案 »
- 超链接转换为另存为
- jquery中的data函数到底有什么用?
- flash播放器的样式
- 问段js不可操作的问题
- 如何实现javascript 脚本的隐藏,类似sina blog 的发表新文章页面
- 去年遇到的问题,一直羞于问大家!!!表格问题。谢谢了!
- 调用html geolocation的js使用手机浏览器就能调用成功,pc的浏览器就不能,为什么呢?
- 关于 弹出窗口的问题
- 有个父子页面控件交互的问题呀,,,,等ing.........
- 关于按回车的问题(进来就可以拿分的问题)
- Venkman JavaScript Debugger在firefox中调试时,document.title得到的总是"JavaScript Debugg"
- javascript 小数问题
<html>
<head>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function creatXHR(){
if (document.all){
try {return new ActiveXObject('Msxml2.XMLHTTP');}
catch(e){return new ActiveXObject('Microsoft.XMLHTTP');};
}
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
}
function getText(node){
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);
}
function done(xhr){
var text = getText(xhr.responseXML.getElementsByTagName('div')[0]);
document.getElementById("aa").innerHTML = text;
}
</script>
</head>
<body>
<div id="aa" onClick="a();" style="width:400px; height:400px; background-color:#0066FF;"></div>
<script type="text/javascript">
function a(){
var xhr = creatXHR();
xhr.open('GET', 'info.xml?r='+ escape(new Date()), false);
xhr.send(null);
try {
done(xhr);
} catch (e) {
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200) {
done(xhr);
}
}
}
}
</script>
</body>
</html>
<head>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function creatXHR(){
if (document.all){
try {return new ActiveXObject('Msxml2.XMLHTTP');}
catch(e){return new ActiveXObject('Microsoft.XMLHTTP');};
}
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
}
function getText(node){
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);
}
function done(xhr){
var text = getText(xhr.responseXML.getElementsByTagName('div')[0]);
document.getElementById("aa").innerHTML = text;
}
</script>
</head>
<body>
<div id="aa" onClick="a();" style="width:400px; height:400px; background-color:#0066FF;"></div>
<script type="text/javascript">
function a(){
var xhr = creatXHR();
xhr.open('GET', 'image-flow.xml?r='+ escape(new Date()), false);
xhr.send(null);
try {
done(xhr);
} catch (e) {
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200) {
done(xhr);
}
}
}
}
</script>
</body>
</html>
如果去掉try catch 判断,直接done(xhr),就会报以下行缺少对象的错误。
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);
把
function done(xhr){
var text = getText(xhr.responseXML.getElementsByTagName('div')[0]);
document.getElementById("aa").innerHTML = text;
}改成 function creatXHR(){
if (window.ActiveXObject) return new window.ActiveXObject('Microsoft.XMLHTTP');
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
} function done(xhr){
var text = xhr.responseXML.getElementsByTagName("div")[0].childNodes[0].xml;
document.getElementById("aa").innerHTML = text;
}
没,调用getText()函数,执行以下语句就断了
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);所以alert(text)没有效果
不是,是C:\Documents and Settings\Administrator\桌面\7657252.html
FF,SAFARI都是file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/7657252.html方式请问怎么调运行方式?调成这个或者http://localhost/xx.html这种方式
当然要建立服务器