I’m trying to better understand Cross Site Scripting and lets use:
http://api.beatport.com/crossdomain.xml as the example.
The XML lists that all domains are allowed access. However when I make the request from within my HTML page (or from within the console) it will fail with an error similar to:
XMLHttpRequest cannot load http://api.beatport.com/catalog/tracks. Origin <mydomain> is not allowed by Access-Control-Allow-Origin.
What I find weird though, is if I put the request in the address bar of my browser, the request goes through.
Can someone please explain what is going on and what I need to do to fix this because clearly the API allows access from any domain.
XMLHttpRequestdoesn’t look atcrossdomain.xml, it looks atAccess-Control-Allow-Originheader as mentioned in the error message.So the server needs to send a header like this:
Access-Control-Allow-Origin: *If they don’t send that header (
http://api.beatport.com/catalog/tracksdoesn’t), it will be denied.