0

Does anyone know how to fix this error? I am using jquery 1.6.2

XMLHttpRequest cannot load http://www.reddit.com/.xml. Origin null is not allowed by Access-Control-Allow-Origin.

$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "http://www.reddit.com/.xml",
        dataType: "xml",
        crossDomain: true,
        success: xmlParser
    });

    // ...
});
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Raptrex
  • 3,915
  • 10
  • 49
  • 61
  • Short answer is that `crossDomain` doesn't work out of the box with xml, but it _does_ work with JSONP. Getting it to work with XML requires some additional work. – Ray Toal Aug 25 '11 at 06:28
  • possible duplicate of [Need Help With Getting Cross Domain XML With JavaScript](http://stackoverflow.com/questions/1550839/need-help-with-getting-cross-domain-xml-with-javascript) – Quentin Aug 25 '11 at 06:32
  • Hi, I agree with Ray, see the following webpage for more detailed info: http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/ Regards – Neil Aug 25 '11 at 06:38
  • I guess I can use the json version of the reddit api – Raptrex Aug 25 '11 at 06:39

2 Answers2

1

Use zrssfeed it'll make your life a lot easier, jsFiddle.

$('#test').rssfeed('http://www.reddit.com/.xml');
Sinetheta
  • 9,189
  • 5
  • 31
  • 52
0

its because same-origin-policy create a server side proxy and have that proxy query the webservice and return your ajax request the xml response

Rafay
  • 30,950
  • 5
  • 68
  • 101