E
E
extazyplayer2021-05-17 17:50:49
JavaScript
extazyplayer, 2021-05-17 17:50:49

How to fix XMLHttpRequest: No 'Access-Control-Allow-Origin' header is present on the requested resource?

I'm trying to get a soap xml response from the server, and I'm getting an error:
Access to XMLHttpRequest at 'Api URL' from origin 'URL of the page I'm sending from' has been blocked by CORS policy: Response to preflight request doesn't pass access control check : No 'Access-Control-Allow-Origin' header is present on the requested resource.

First, I used Postman, in which I sent a soap xml document, and in the headers I wrote 'SOAPAction', 'urn:microsoft-dynamics-schemas/Codeunit/WS:GetSelfAssessment', this is the header with my soap action. However, I got the correct answer. 60a2821d986e0067995127.png

On the page I do the same, I added the headings, why do I have an error?

What I already tried:

//const url = ''; // мой urlздесь
                
                var xhr = new XMLHttpRequest();
                
                xhr.open("POST", url, false);
                xhr.withCredentials = true;
                xhr.setRequestHeader('SOAPAction', 'urn:microsoft-dynamics-schemas/Codeunit/WS:GetSelfAssessment');
                xhr.setRequestHeader('Content-Type', 'text/xml');
                xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
                xhr.setRequestHeader('Access-Control-Allow-Headers', '*');
                
                xhr.send();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-05-17
@Rsa97

This question comes up here several times a day.
These headers must be returned by the server. Google CORS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question