Having issues getting data back from a http post request to an API I've been building. Throws the error:
XMLHttpRequest cannot load (URL to API here). No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
Here's the Angular code on the client side:
$http.post('MyAPI'sURLHere', {date: $scope.information.PubDate})
.then(function(response){
console.log(response);
}, function(error){
console.log(error);
});
And here's the Node server side code for my API:
app.post('/getThing', function(req, res){
var date = req.body.date;
console.log(typeof date);
var query = Overquery
var query2 = "alter session set nls_date_format = 'MM/dd/yyyy'";
console.log(query);
oracleDB.execute(query2, function(err, result){
if(err){
console.log(err.message);
}
else{
console.log(result);
}
});
oracleDB.execute(query, function(err, result){
if(err){
console.log(err.message);
}
else{
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'POST');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
console.log(result.rows);
res.json(result.rows);
}
});
});
First time building an API so any suggestions and help would be greatly appreciated!