Answer the question
In order to leave comments, you need to log in
How to fix AJAX access not allowed error?
Good evening. I got the following error:
Failed to load https://*domain1*/wp-admin/admin-ajax.php : The 'Access-Control-Allow-Origin' header has a value ' https://*domain2*/ ' that is not equal to the supplied origin. Origin '*domain2*' is therefore not allowed access.
@header( 'Access-Control-Allow-Origin: *' );
Failed to load https://*domain1*/wp-admin/admin-ajax.php : The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin ' https://*domain2* ' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
@header( 'Access-Control-Allow-Origin: https://*domain2*' );
and got the error that I indicated at the very beginning Answer the question
In order to leave comments, you need to log in
Nevertheless, as a result of dancing with a tambourine over the code, I found a solution:
@header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
@header( 'Access-Control-Allow-Origin: https://domain.com' ); // Без слеша в конце. Не знаю почему, но это важно
@header( 'Access-Control-Allow-Credentials: true' );
and if the domain is normal to write?
@header( 'Access-Control-Allow-Origin: https://domain2.com' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question