0
I developed a API REST
in Node.js
and I need to use it in my front-end.
I’ve installed the library Cors and enabled on my server but continues to give the error of access when making the request with AJAX
.
Enabling CORS on Node.js
const cors = require('cors');
const app = express();
app.use(cors());
Calling the API in Jquery
$.ajax({
type:'GET',
url: `localhost:3030/api/admin/employees`,
data:fd,
cache:false,
contentType: false,
processData: false,
success:function(data){
console.log("success");
console.log(data);
},
});
Error in Chrome console
Access to Xmlhttprequest at 'localhost:3030/api/admin/Employees? _=1573153461164' from origin 'http://localhost' has been blocked by CORS policy: Cross origin requests are only supported for Protocol schemes: http, data, Chrome, Chrome-Extension, https
Try swapping the url for
http://localhost:3030/api/admin/employees
– Felipe Avelar
Great, now it’s working =D
– Victor Hugo