Answer the question
In order to leave comments, you need to log in
How to correctly send an Ajax (POST) request to another site?
Hello, first I will describe the situation.
There is a site, it provides some services through the API, everything is fine with that. It also provides a free service for which there is no API, but I know where the POST request goes and what data needs to be specified in order for the server to process it correctly. Unfortunately, when I send a request to a web page, I get an error that the CORS policy is violated.
Mistake:
Access to XMLHttpRequest at 'САЙТ НА КОТОРЫЙ ОТПРАВЛЕН ЗАПРОС' from origin 'Мой сайт' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
$.ajax({
url: 'САЙТ НА КОТОРЫЙ ОТПРАВЛЕН ЗАПРОС',
type: 'post',
data: "action=freeOrder&список параметров"
});
Answer the question
In order to leave comments, you need to log in
It's not an error, it's the server you're sending to that doesn't agree to accept requests from anywhere other than its own domain. If the server belongs to you, and it is Apache, writing the command to the .htaccessHeader set Access-Control-Allow-Origin "*"
file will save you
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question