responseXML的总是空 [英] responseXML always null

查看:235
本文介绍了responseXML的总是空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯使用的Firefox 3.6.10,和萤火虫调试

Im using firefox 3.6.10, and firebug to debug

所以,这里是我的code:

So, here is my code:

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url,false);
xmlhttp.setRequestHeader('Content-Type',  'text/xml');
xmlhttp.send(null);
alert(xmlhttp.responseXML);

responseXML的总是空的,我已经试过了来自不同领域的多个网址。我也尝试过异步方式,这是同样的结果。在的responseText 总是正确返回,没有问题吧。

responseXML is always null, and i've tried it on several URLs from different domains. I have also tried it asynchronously, it's the same result. The responseText is always properly returned, no problems with it.

我的目标是让在 responseXML.documentElement

感谢您的帮助。

编辑-----------
这个JavaScript code是从Greasemonkey的userscript执行的,我做了苏特其同源的请求的URL。此外,我试图从Firebug的控制台执行,也确保了原产地政策。两个同样的错误。
得讨厌的JavaScript。

EDIT-----------
This javascript code was executed from a Greasemonkey userscript, i made surte its the same origin as the requested url. Also i tried executing from firebug console, again ensuring the origin policy. Same error on both.
Gotta hate javascript.

推荐答案

我敢打赌,你违反了同源策略。

I bet you are violating the same origin policy.

有关XHRs,你必须有相同的协议,域名,端口等,所以,如果你正在运行的本地主机上的应用程序:8080 /应用程序,你不能AJAX来www.cnn.com

For XHRs, you must have the same protocol, domain, port, etc. So if you are running an app on localhost:8080/app, you CANNOT ajax to www.cnn.com.

不同的浏览器处理这种不同;我看到法郎做你的描述,这是要求看似正常返回,但没有数据...

Different browsers handle this differently; I have seen FF do what you describe, which is the request appears to return normally but there is no data...

这篇关于responseXML的总是空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆