1
resposta

Fica dando erro no CORS

o erro: Access to XMLHttpRequest at 'https://api-pacientes.herokuapp.com/pacientes' from origin 'null' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains the invalid value 'null//undefined'.

var botaoAdicionar = document.querySelector("#buscar-pacientes");

botaoAdicionar.addEventListener("click", function() {
    var xhr = new XMLHttpRequest();

    xhr.open("GET", "https://api-pacientes.herokuapp.com/pacientes");

    xhr.addEventListener("load", function() {
        console.log(xhr.responseText);
    });

    xhr.send();
});
1 resposta

Fala ai Gabriel, tudo bem? Fiz um teste aqui em uma aplicação JavaScript e deu tudo certo, segue código de exemplo:

fetch('https://api-pacientes.herokuapp.com/pacientes')
    .then(resp => resp.json())
    .then(console.log)

Foi logado o array de retorno com todos os pacientes.

Espero ter ajudado.