[英]XML accessible from URL line but not from script
When I type a certain URL in FF, I get the XML returned displayed on the screen, so the web service is apparently working. 当我在FF中键入某个URL时,我将返回的XML显示在屏幕上,因此Web服务显然可以正常工作。 However, when I try to access it from a local HTML document running JS, I get unexpected behavior.
但是,当我尝试从运行JS的本地HTML文档访问它时,出现了意外的行为。 The returned code is "200 OK" but there's no text (or rather it's an empty string) nor xml (it's
null
) in the response sections according to FireBug. 返回的代码为“ 200 OK”, 但是根据FireBug,响应部分中没有文本(或者更确切地说,它是一个空字符串)或xml(它为
null
)。
This is how I make the call. 这就是我打电话的方式。
var httpObject = new XMLHttpRequest();
httpObject.open("GET", targetUrl, true);
httpObject.onreadystatechange = function () {
if (httpObject.readyState == 4) {
var responseText = httpObject.responseText;
var responseXml = httpObject.responseXML;
}
}
httpObject.send(null);
Why does it happen and how do I tackle it? 为什么会发生,我该如何解决?
That may be an HTTP header problem (eg missing Accept
header); 这可能是HTTP标头问题(例如缺少
Accept
标头); observe the headers sent by FF (you can use Firebug for that) and try to replicate them in your script ( setRequestHeader
). 观察FF发送的标头(可以使用Firebug),并尝试在脚本中复制它们(
setRequestHeader
)。
Otherwise, that may be a "same origin policy" problem. 否则,这可能是“相同来源策略”的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.