I have been struggling for hours to access a resource from a different domain. I came across information on that suggests using the XMLHttpRequest
in a CORS-enabled browser should solve the issue. However, I keep encountering the error message "
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.nczonline.net/. This can be fixed by moving the resource to the same domain or enabling CORS.
"
Even though I am using Firefox 34 which is expected to support CORS according to http://caniuse.com/#feat=cors, the problem persists.
I'm attempting a basic example from
If you take a look at the code snippet below:
<script type="text/javascript">
function log(msg){
var output = $('#output');
output.text(output.text() + " | " + msg);
console.log(msg);
}
function createCORSRequest(method, url){
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr){
xhr.open(method, url, true);
log("'withCredentials' exist in xhr");
} else if (typeof XDomainRequest != "undefined"){
xhr = new XDomainRequest();
xhr.open(method, url);
log("XDomainRequest is being used");
} else {
xhr = null;
log("xhr is null");
}
return xhr;
}
function main(){
log("Attempting to make CORS request");
var request = createCORSRequest("get", "https://www.nczonline.net/");
if (request){
request.onload = function(){
log("LOADED!");
};
request.send();
}
}
$(window).load(function(){
main();
});
</script>
In my tests, the following output was generated:
Attempting to make CORS request
'withCredentials' exist in xhr
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.nczonline.net/. This can be fixed by moving the resource to the same domain or enabling CORS.
Running the code on JSFiddle via https://jsfiddle.net/zf8ydb9v/ yielded the same results. Could there be another setting that needs to be adjusted besides using XMLHttpRequest for CORS to work properly?