Jquery.get 无法从 RESTful 服务检索 XML
我正在尝试使用 Jquery get 方法从 REST 服务获取 XML 文档,但它似乎无法下载。大约 11 秒后,连接就断开了,我收到了一份空白文档。我已经通过浏览器访问该 URL 进行了测试,它可以工作(尽管加载需要 4 分钟)。
$(document).ready(function()
{
$.get(
siteUrl,
function(data) { parseXml(data); }
);
});
我考虑过使用ajax方法,因为你可以设置超时,但应用相同的域策略,限制我使用它。有什么想法吗?
I'm trying to get an XML document from a REST service using the Jquery get method, but it doesn't seem to be able to download. After only about 11 seconds, the connection dies and I receive a blank document. I've tested out the URL by accessing it through the browser, and it works (even though it takes 4 minutes to load).
$(document).ready(function()
{
$.get(
siteUrl,
function(data) { parseXml(data); }
);
});
I've considered using the ajax method, because you can set the timeout, but the same domain policy applies, restricting me from using it. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 jQuery.get() 的文档
所以我不确定您的意思 “但是应用了相同的域策略,限制我使用它。” 但是如果
$ .get
有效,$.ajax
也有效From documentation for jQuery.get()
So I'm not sure what you mean by "but the same domain policy applies, restricting me from using it." But if
$.get
works, so will$.ajax
好的,.get 和 .ajax 将无法工作,因为它们不在同一域下,因此违反了 同源政策。
为了解决这个问题,我们可以使用 .getJson 方法(更多信息请参见 IBM 的网站)
但是,在我的情况下,所需的输出不是 Json,因此我们可以使用类似 来自 Yahoo 的 YQL 来完成...或者仅在您的域上使用代理服务器。
Okay, .get and .ajax will not work since they are not under the same domain, thus violating the Same Origin Policy.
To get around this, we can use the .getJson method (more information found on IBM's site)
However, in my situation, the desired output is not Json, thus we can use something like YQL from Yahoo to accomplish... or just use a proxy server on your domain.