OK, I've been at this for hours now! And I've read every conceivable link I can find on the subject, but I still CAN NOT get it to work, and it is driving me slowly insane.
I'm making an AJAX request (From my domain) to an API (on another domain), but all I keep getting back in the console log is (obviously I've modified the exclude any domains etc):
XMLHttpRequest cannot load https://[APIPROVIDER]/something.json?options. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://[MYDOMAIN].com' is therefore not allowed access.
This is my code
$(document).ready(function() {
function step1(){
$.ajax({
url: 'getit.php',
method: 'get',
dataType : 'json',
success: function(data){
step2(data.url);
},
error: function(jqXHR, status, error) {
console.log(error);
}
});
}
function step2(url){
$.ajax({
url: url,
type: 'get',
dataType : 'json',
success: function(data){
console.log(data);
},
error: function(xhr, status, error) {
console.log(error);
}
});
}
step1();
});
I've tried, ajaxSetup (to set headers), doesn't help. I've tried, headers: { 'Access-Control-Allow-Origin': '*' }. I've tried crossDomain: true. I've tried removing dataType : 'json'.
Like I said, this is slowly driving me mad. Mostly because this is the only thing stopping me from moving on and working with presenting the response. And it's so close, I just keep getting that error, no matter what I do. I've read several articles on CORS, Access-Control-Allow-Origin in headers. I still don't understand WHY I get this error.
Any help here is greatly appreciated! /desperate