-1
First of all, I wanted to say that I’m developer . net, so I’m kind of lost in what I’m doing.
If I understood correctly, I downloaded Node.js and inside the Node.js prompt I gave a CD in the folder of my project (where is my index.html and index.js), after the cd gave an npm start, then it went up as localhost:9966 and I am using the page since then, all apparently working well well.
But now I’m locked into a GET/POST request with AJAX, and the weirdest thing, when I do a GET for the VIACEP api I get the return normally, but when I send it to my api. net he gives me error of CORS.
Follows the Code
function getCep(){
$.ajax({
url: 'https://webchatapi.azurewebsites.net/api/atendimento/solicitacoes/',
//url: 'https://viacep.com.br/ws/09831380/json/ ',
headers: {'content-type': 'application/json'},
crossDomain: true,
type: "GET",
dataType: "json",
success: function (data) {
console.log(data);
},
error: function () {
console.log("error");
}
});
}
When I use the VIACEP url:
When I use my . net api
result of my api when get by Chrome/Postman:
I’ve been stuck in this for two days, I don’t know what to do, thank you !
Related: CORS error with different domains
– Icaro Martins
Good afternoon Icaro, I had already visited this link before asking the question, as you can see in my code already includes "crossDomain: true" and would not like to change my application to extension, also already tried to use jQuery.support.Cors = true, however do not know how to enable CORS in Node.js as informed "res.setHeader('Access-Control-Allow-Origin', '*'); ", where I put this code?
– Renan Pinheiro
I put the link only as related. = D -- On your question it seems to me that your site
localhost
this one withres.setHeader...
, but this error is being caused by the sitewebchatapi.azurewebsites.net
it is he who is refusing the requisitions of other domains.– Icaro Martins
I figured it was something with the API, but in it I’ve already enabled the Cors :(
– Renan Pinheiro