responseXML 始终为空

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

问题描述

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)