I'm accessing an external API from Javascript in my app and I get this error:
Failed to load http://www.myapp.com//api/v1/syndication/categories?output=json: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://local.myapp.com' is therefore not allowed access. The response had HTTP status code 400.
function MakeAPIRequest(requestUrl, requestData, callback) {
$.ajax({
beforeSend: function(xhr){
xhr.setRequestHeader('Access-Control-Allow-Origin', 'http://local.myapp.com');
xhr.setRequestHeader('Token', apiKey);
},
type: "GET",
url: requestUrl,
data: requestData,
dataType: "json",
success: function(json){
callback(json);
}
});
}
Could be the API doesn't accept an "OPTIONS" request? This is the server response:
{"error":"Bad Request - Only accepts get requests","code":1009}