CORS error on Ajax Request in WordPress Themes

i create a child from existing wordpress themes, and create a new custom page. after that i used ajax to call a rest api from other subdomain. and i got error

i used ajax like this

$.ajax({
type: ‘POST’,
contentType: ‘application/json’,
url: endpoint,
data: JSON.stringify({ “kompas_id_post_title”: request.term }),
success: function (data) {
console.log(data);
}
});

I got an error like this

Failed to load https://{domain}: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://silo.kompas.id‘ is therefore not allowed access. The response had HTTP status code 405.

is there any way to solved the problem?

Read more here:: CORS error on Ajax Request in WordPress Themes

Leave a Reply

Your email address will not be published. Required fields are marked *