reason: cors header ‘access-control-allow-origin’ missing - Access-Control-Allow-Origin error sending a jQuery Post to Google API's
I had exactly the same issue and it was not cross domain but the same domain. I just added this line to the php file which was handling the ajax request.
<?php header('Access-Control-Allow-Origin: *'); ?>
It worked like a charm. Thanks to the poster
I read a lot for the 'Access-Control-Allow-Origin' error, but I don't understand what I have to fix :(
I'm playing with Google Moderator API, but when I try to add new serie I receive:
XMLHttpRequest cannot load https://www.googleapis.com/moderator/v1/series?key=[key] &data%5Bdescription%5D=Share+and+rank+tips+for+eating+healthily+on+the+cheaps! &data%5Bname%5D=Eating+Healthy+%26+Cheap &data%5BvideoSubmissionAllowed%5D=false. Origin [my_domain] is not allowed by Access-Control-Allow-Origin.
I tried with and without callback parameter, I tried to add 'Access-Control-Allow-Origin *' to the header. And I don't know how to use $.getJSON here, if apply, because I have to add the Authorization header and I don't know how to do it without beforeCall from $.ajax :/
Any light for this darkness u.u?
That's the code:
Yes, the moment jQuery sees the URL belongs to a different domain, it assumes that call as a cross domain call, thus
crossdomain:true is not required here.
Also, important to note that you cannot make a synchronous call with
$.ajax if your URL belongs to a different domain (cross domain) or you are using JSONP. Only async calls are allowed.
Note: you can call the service synchronously if you specify the
async:false with your request.