I am trying to build a rest client to POST data to Redmine API. I don't think i could change anything on Redmine(sever side) API. to give access. I have installed Redmine bitnami stack locally(Redmine -> localhost/redmine). And client side files are on localhost:8080
$(document).ready(function(){
$("#submit").on('click', function(){
// send ajax
$.ajax({
url: 'http://localhost/redmine/projects.json',
type : "post",
crossDomain: true,
dataType : 'json',
headers: { 'X-Redmine-API-Key': 'admin' },
data : JSON.stringify({
"project": {
"name": "MANOJ",
"identifier": "MANOJ-perera",
"description": "This is a des"
}
}),
success : function(result) {
alert("Sucess");
console.log(result);
},
error: function(xhr, resp, text) {
console.log(xhr, resp, text);
}
})
});
});
I am getting following error.
XMLHttpRequest cannot load http://localhost/redmine/projects/11n. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 404.
How do i solve this issue. Please help.
Solved by bringing both hosts to a common platform without changing anything on severside. Copied all the data in localhost:8080 to localhost. In my case Redmine bitnami stack was in localhost and web application i develop was in localhost:8080 brought all the webapp files to C:\Bitnami\redmine\apache2\htdocs\ and it solved.