var settings = {
"url": "https://siteExemplo.com.br//api/token",
"method": "GET",
"timeout": 0,
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"UserName": "nameExemplo",
"Password": "senhaExemplo",
"grant_type": "password"
}
};
$.ajax(settings).done(function (response) {
console.log(response);
});
está dando o seguinte erro no console:
"Access to XMLHttpRequest at 'http://site.com.br' from origin from origin 'http://localhost:888' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."
Pesquisei a respeito modifiquei diversas vezes, converti minha pagina html para php e coloquei headers la no inicio com alguns dados seguindo tutoriais, mas n sei mais o que fazer.
Uso o programa Vertrigo como servidor (apache). Minha pagina ficou assim:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With"
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<!--Conexão com js-->
<!--título da aba da pagina-->
<!--conexão do css (estilo)-->
<style>
</style>
</head>
<div id="root"></div>
<body>
</body>
</html>