0

I can't figure out how to make a cross domain ajax call. My code is this:

$.ajax({
    type: "GET",
    url: "http://csgolounge.com/availableweapons",
    cache: false,
    dataType: "xml",
    success: function(data) {
        console.log(data);
    }
});

But this gives me this error, due to the same-origin policy:

XMLHttpRequest cannot load http://csgolounge.com/availableweapons?_=1413931403643. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 

I've seen a few other solutions using jsonp but this is xml data, not json. I've seen others using a php proxy but I've never used php before. I just want to be able to read the xml at http://csgolounge.com/availableweapons into a variable so I can parse it on my own.

  • this answer duplicate here: http://stackoverflow.com/questions/16989505/jquery-cross-domain-ajax – Yehia Elhawary Oct 21 '14 at 22:51
  • You have to either configure the destination to allow cross domain requests (with something liKe CORS) or you HAVE to use JSONP (you can wrap the XML into JSON). That's what the browser requires in order to do a cross-origin request. JSONP requires a cooperating server that supports JSONP. The whole point of this is that cross-origin requests are ONLY permitted if the server specifically allows it for security/spoofing reasons. The only other option is to use another server that does allow cross-origin requests to get the data for you. – jfriend00 Oct 21 '14 at 22:59
  • one other solution is use a third party proxy like Yahoo's YQL – charlietfl Oct 21 '14 at 23:01

0 Answers0