CORS policy: Response to preflight request - JavaScript/SharePoint Server

Copper Contributor
I have an issue connecting to my SharePoint server. This issue occurs whenever I try connecting my code from the frontend to the SharePoint server, I do not have a backend for this. 
Basically, I am trying to get the SharePoint API results directly via JavaScript. I am uncertain why this error keeps popping up. Is there something wrong with my IIS configuration? Please do help me on this! Thank you!

This is my IIS configuration in the SharePoint Server:
  <add name="X-Content-Type-Options" value="nosniff" />
  <add name="X-MS-InvokeApp" value="1; RequireReadOnly" />
  <add name="Access-Control-Allow-Origin" value="*" />

Error Message:
My code is as follows:


function simpleSearchAPICall(searchUrl) {

                url: searchUrl,
                type: "GET",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                complete: function(response){
                    console.log("URL", searchUrl)
                    // Handle the response data here
                error: function(xhr, status, error) {
                    // alert("An error occurred while making the request.");






0 Replies