I have an issue with CORS policy. The request to retrieve URL is being blocked. I tried everything (Access-Control-Allow-Origin: * in .htaccess, theme's function.php, theme's header and wp-config.php file as well) and nothing seems to work. It works perfectly on localhost though.

Here's my JS AJAX script:

        type: "POST",
        url: Theme_Variables.ajax_url,
        data: ({
            action: 'myaction',
            postID: postID, 
            price: price,
        success: function(response) {
            response = response.slice(0, -1);
            $('.Link').prop('href', response);
            //window.location = response;
        error: function(errorThrown){
            console.log( 'error' + JSON.stringify(errorThrown));

The error I get is: Access to XMLHttpRequest at 'https://someotherurl.com' (redirected from 'https://myurl.com/wp-admin/admin-ajax.php') from origin 'https://myurl.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin.

Can anyone help? It would'nt be strange if it didn't work in localhost, but it does...

1 Answer 1


The problem was that the PHP AJAX function was redirecting to another page, which caused these issues. I decided to just generate a link instead of redirecting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.