Access-Control-Allow-Origin problem in XHR with Javascript

Asked

Viewed 651 times

0

I am trying to consume an API via XHR and Javascript that comes from SAP HANNA and it is returning these errors:

inserir a descrição da imagem aqui

The funny thing is that with Postman it returns me the values, but with JS and XML it gives the above error..

Follow the simple code:

    let xhr = new XMLHttpRequest();
    xhr.withCredentials = true;
    xhr.addEventListener("readystatechange", function () {
        if (xhr.readyState === 4) {
          console.log(xhr.responseText);
        }
      });

    xhr.open("GET", "https://aliansce.apimanagement.us2.hana.ondemand.com/bot/v1/fatVenda.xsjs?Shop='BSC'&PeriodoAte=201807", true);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.setRequestHeader("Apikey", "KEY");
    xhr.setRequestHeader("Authorization", "Basic AUTH=");
    xhr.setRequestHeader("cache-control", "no-cache");
    xhr.setRequestHeader("postman-token", "TOKEN");

    xhr.send(null);
  • Are you complaining about Cross-Origin, tried to add in header?

  • Take a look at this answer here: https://answall.com/a/126341/3999

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.