-1

I'm trying to obtain information about a sent notification. But i don't know exactly how to proceed. This is my javascript code:

    function obtenerInformacion(uuid){
        var xhr = new XMLHttpRequest();
        xhr.withCredentials = true;

        xhr.addEventListener("readystatechange", function () {
          if (this.readyState === 4) {
            console.log(this.responseText);

      }
    });

    xhr.open("POST", "https://api.ionic.io/push/notifications/"+uuid);
    xhr.setRequestHeader("Access-Control-Allow-Origin","*");
    xhr.setRequestHeader("Access-Control-Allow-Methods","GET,PUT,POST,DELETE,OPTIONS");
    xhr.setRequestHeader("Access-Control-Allow-Headers","Content-Type");
    xhr.setRequestHeader("content-type", "application/json");
    xhr.setRequestHeader("authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxN2FlYWZlMC02ZTg4LTQ3NDItOWMxMC04ZTczY2IwNWU4NGMifQ.n25i9yTWdqFauTd6xnfW0Uats_x7EvnB42KhoFu8E04");
    xhr.send();
}

I'm getting this error:error

Sorry for my english.

EDIT: Fixed. Apparently the request had to be made by GET

xhr.open("GET", "https://api.ionic.io/push/notifications/"+uuid);

xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxN2FlYWZlMC02ZTg4LTQ3NDItOWMxMC04ZTczY2IwNWU4NGMifQ.n25i9yTWdqFauTd6xnfW0Uats_x7EvnB42KhoFu8E04");
xhr.send();

Thank you very much to all

i02mike
  • 1
  • 1

2 Answers2

0

Try downloading and enabling this chrome plugin.

maninak
  • 2,633
  • 2
  • 18
  • 33
0

The Access-Control-Allow-Headers configuration needs to be set by the server when it sends to message to you (the client).

See this reply for more info.

maninak
  • 2,633
  • 2
  • 18
  • 33
  • Thank you very much. If I understood correctly the server that sends in its response, it is not the client that sends them – i02mike Jun 08 '17 at 12:20
  • Yes, as I said earlier these headers need to be set by the *server* in his response. Whatever acess-control headers the client sets are irrelevant and are just ignored. So this means that you need to make the change in your backend, at your webserver. Hope this answers your question. – maninak Jun 08 '17 at 12:25