I am trying to access an API via my localhost using the following code:
$.ajax({
url: "http://domain.xxx.net/api/tokens.json?email=xxx@xxx.net&password=xxx",
//method: "GET",
headers: { "Accept": "application/xml", "Content-Type": "application/xml", "Access-Control-Allow-Origin": "*"},
dataType: "JSON",
success:function(data){
alert(data);},
success:function(e){
alert(e.message);}
});
I have read over the internet that this is not possible due to the error below.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
After some research it was said that i can use JSONP or CORS. I was able to use JSONP however, I am getting a js error because the API supports only both JSON & XML and not JSONP. Now I am trying to convert my ajax call to CORS but I simply can't understand the syntax. I always get the same error about the 'Access-Control-Allow-Origin'.
I hope someone can help me translate this one. Thanks.