Jquery.get 无法从 RESTful 服务检索 XML

发布于 2024-08-29 01:33:56 字数 319 浏览 1 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

太阳公公是暖光 2024-09-05 01:33:56

来自 jQuery.get() 的文档

这是一个简写的 Ajax 函数,相当于:

$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

所以我不确定您的意思 “但是应用了相同的域策略,限制我使用它。” 但是如果 $ .get 有效,$.ajax 也有效

From documentation for jQuery.get()

This is a shorthand Ajax function, which is equivalent to:

$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

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

小…楫夜泊 2024-09-05 01:33:56

好的,.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文