responseXML 始终为空

responseXML always null(responseXML 始终为空)
本文介绍了responseXML 始终为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我用的是firefox 3.6.10,用firebug来调试

Im using firefox 3.6.10, and firebug to debug

所以,这是我的代码:

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

responseXML 始终为空,我已经在来自不同域的多个 URL 上尝试过它.我也尝试过异步,结果是一样的.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 代码是从 Greasemonkey 用户脚本执行的,我将其设置为与请求的 url 相同的来源.我也尝试从萤火控制台执行,再次确保原产地政策.两者都有相同的错误.
讨厌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.

对于 XHR,您必须具有相同的协议、域、端口等.因此,如果您在 localhost:8080/app 上运行应用程序,则不能 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.

不同的浏览器有不同的处理方式;我看到FF按照你的描述做了,就是请求看起来正常返回但是没有数据...

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 始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)