-2

I am trying to call the POST REST API from the office outlook web add-in using ajax calls, for target url Configured the app domains in the manifest.xml file but I am facing same CORS issue.

Access to XMLHttpRequest at 'https:' from origin 'https:' has been blocked by CORS policy: Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.

I couldn't find the reason and what is wrong with it.

MessageRead.js code

$.ajax({
            type: "POST",
            dataType: "json",
            url: "<target url>",
            contentType: 'application/json',
            crossDomain: true,
            headers:
            {
                'X-Database': 'aln_template',
            },
                          data: {
                //id: "1598521065618",
                id: (new Date()).getTime(),
                method: "execute",
                params: params
            },
            success: function (data1) {
     }
});
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

Access-Control-Allow-Origin is a response header, not a request header. You can’t send that particular header with your post request, which is why it’s being rejected.

Nick Dawes
  • 2,089
  • 1
  • 13
  • 20
  • Nick Dawes, if I remove Access-Control-Allow-Origin from request header I am getting another CORS error, Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response. – Prashanth reddy Sep 16 '20 at 04:48