views:

46

answers:

2

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?

A: 

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

R0MANARMY
A: 

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.

Anton
@Anton: BTW, http://api.jquery.com/jQuery.getJSON/ is also just a wrapper around the ajax call. It only gets treated as jsonp if you have a `callback=?` on the end of the url.
R0MANARMY
That's right. With the YQL, you have to add that to your URL, so it should still be fine.
Anton