A
A
Anastasia2021-04-01 04:00:40
CORS
Anastasia, 2021-04-01 04:00:40

How to disable CORS on openserver?

I want to make a request to another site via js from localhost. Here is my js:

js
// Отправка данных на сервер
function send(event, asite){
console.log("Отправка запроса");
event.preventDefault ? event.preventDefault() : event.returnValue = false;
var req = new XMLHttpRequest();
req.open('POST', asite, true);
req.onload = function() {
  if (req.status >= 200 && req.status < 400) {
  json = JSON.parse(this.response);
    	console.log(json);
    // Если не удалось связаться
    } else {alert("Ошибка сервера. Номер: "+req.status);}}; 

// Если не удалось отправить запрос. Стоит блок на хостинге
req.onerror = function() {alert("Ошибка отправки запроса");};
req.send(new FormData(event.target));
}

And when sending the request, the following error message is returned:
...has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


I read on the net that you need to create a .htaccess file and write the line there Access-Control-Allow-Origin:*. I do this, but in the end my page does not open at all (error 500).

What to do to make everything work?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question