This topic contains 2 replies, has 2 voices, and was last updated by  onyxtacular 2 years, 11 months ago.

CORS policy: No ‘Access-Control-Allow-Origin’ display map not loading

  • I recently migrated to a new server. Since the migration the map does not display on the page, the only thing seen is a loading icon. Where should I start to trouble shoot.

    The console reports these errors:

    Access to XMLHttpRequest at ‘https://greatnortherncabinetry.com/wp-content/plugins/superstorefinder-wp/ssf-wp-xml.php?wpml_lang=&t=1638133008105′ from origin ‘https://www.greatnortherncabinetry.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
    jquery.min.js?ver=3.6.0:2

    GET https://greatnortherncabinetry.com/wp-content/plugins/superstorefinder-wp/ssf-wp-xml.php?wpml_lang=&t=1638133008105 net::ERR_FAILED 301

    I’ve tried adding this the the wordpress functions.php file:

    add_action('init', 'handle_preflight');
    function handle_preflight() {
    $origin = get_http_origin();
    if ($origin === 'https://greatnortherncabinetry.com') {
    header("Access-Control-Allow-Origin: yourfrontenddomain");
    header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
    header("Access-Control-Allow-Credentials: true");
    header('Access-Control-Allow-Headers: Origin, X-Requested-With, X-WP-Nonce, Content-Type, Accept, Authorization');
    if ('OPTIONS' == $_SERVER['REQUEST_METHOD']) {
    status_header(200);
    exit();
    }
    }
    }
    add_filter('rest_authentication_errors', 'rest_filter_incoming_connections');
    function rest_filter_incoming_connections($errors) {
    $request_server = $_SERVER['REMOTE_ADDR'];
    $origin = get_http_origin();
    if ($origin !== 'https://greatnortherncabinetry.com') return new WP_Error('forbidden_access', $origin, array(
    'status' => 403
    ));
    return $errors;
    }

    and I’ve added this the .htaccess file:

    <IfModule mod_rewrite.c>
    Header set Access-Control-Allow-Origin "*"
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    Alex
    StaffUser Level

    Hi there,

    Thank you for your inquiry, if you’re getting permission error “Access to XMLHttpRequest”, try to contact your hosting provider (for both domains) to allow access for cross origins and allow firewall, more details available in this knowldege base article here.

    Cheers,
    Alex

    The server are with the same provider. I did get the error fix though:

    The WordPress Address (URL) & Site Address (URL)
    where different (one was missing the www.)

Tagged: 

The topic ‘CORS policy: No ‘Access-Control-Allow-Origin’ display map not loading’ is closed to new replies.