1

I'm trying to copy some content from my site with Ajax but I'm getting a problem with my cors header.

I'm having a WordPress-Multisite site with subdomains and the ajax call is between these. If the call is made on the same subdomain it is working fine but not if it's between different ones. In my research I added to my htaccess this (on the top):

RewriteEngine On
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>

Also notice: I' having a Linux shared server and my hoster confirmed that my mod_headers are enabled. The call is made in the backend but the htaccess should be loaded anyway right?

You can see my Ajax call below:

$.ajax({
     url: window.location.protocol + '//' + window.location.hostname.replace('en.|de.', '') + '/' + admin_slug + '/network/',
     type: 'GET',
     success: function(res) {
        var data = $.parseHTML(res);  //<----try with $.parseHTML().
        $(data).find( '#menu-settings' ).find( 'ul' ).each(function(){
            $( 'ul.overview_settings-list' ).append($(this).html());
        });

     }
});

But still I'm getting this error:

Access to XMLHttpRequest at 'https://domain.co/dashboard/network/' (redirected from 'https://de.domain.co/dashboard/network') from origin 'https://de.domain.co' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,utils&ver=5.2.2:4 GET https://domain.co/dashboard/network/ net::ERR_FAILED

EDIT Also this didn't work for me:

RewriteEngine On
<IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
   Header set Access-Control-Allow-Headers "Content-Type"
   Header set Access-Control-Allow-Methods "GET"
</IfModule>
Game Unity
  • 125
  • 10

0 Answers0