Noobie here. I'm writing a client script that needs to read an XML file from another domain. I tried using JSONP. I get a 200 response but the client can't access the returned data for some reason. I get two errors:
Resource interpreted as Script but transferred with MIME type text/xml
and
Uncaught SyntaxError: Unexpected token <
Here's the code (I've removed the XML url since it's confidential):
$(document).ready(function() {
$.getJSON("urlOfFilecallback=?", function(data) {
console.log(data)
})
});
When I try to render the data in the console I get:
ReferenceError: data is not defined
How can I fix this? Do I need to use a proxy?
You don't have to write your own proxy. You can use YQL if you want to here is an example how:
here is the jsfiddle check console.log.
(Usage limits of the public YQL API is 2,000 requests/hour per IP)
If you have access to the other domain side, you could also use this approach Cross Domain Request
XML is not allowed for cross-domain requests by default.
However, with a little server-side programming you can create a proxy and load the data within your own domain, and output it as XML.
for more information see this Question