• Resolved Andyt8

    (@andyt8)


    I use SlimStat Analytics at https://blackseals.net with WP 4.8.1 and use for several external pages the tracking code. I adjusted ‘Access-Control-Allow-Origin’ with the “Allow Domains” field. It was working for some time.

    Today I take a look to statistics and missed some requests from myself. So I started searching why…

    At the moment I get an error message in the webbrowser:
    >>>
    XMLHttpRequest cannot load …/wp-admin/admin-ajax.php. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers in preflight response.
    <<<

    For example one external page: https://blog.blackseals.net

    Is there a bug in SlimStat or a mistake by me in the configuration. Please for help.

    best regards,
    Andyt

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Sa?a

    (@stodorovic)

    Hi @andyt8

    I’ve tried to fix some similar issues. It seems as trouble with ORIGIN request (related to WP core). Possible solution could be:

    – Add all external domains ( https://blog.blackseals.net , …) using filter allowed_http_origins.

    – Send header Access-Control-Allow-Headers: for ORIGIN request.

    Possible workaround (for CORS) is (it isn’t perfect):

    add_filter( 'allowed_http_origin', 'xxxxxx_send_cors_headers' );
    
    function xxxxxx_send_cors_headers( $origin ) {
    
            // Access-Control headers are received during OPTIONS requests
            if (  $origin && 'OPTIONS' === $_SERVER['REQUEST_METHOD'] ) {
    
                    if ( isset( $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'] ) ) {
                            @header( 'Access-Control-Allow-Headers: '. $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'] );
                    }
    
            }
    
            return $origin;
    
    }
    

    I hope that helps.

    Regards,
    Sasa

    PS. Please send your current code related to allow domains if it’s possible.

    • This reply was modified 7 years, 7 months ago by Sa?a.
    • This reply was modified 7 years, 7 months ago by Sa?a.
    • This reply was modified 7 years, 7 months ago by Sa?a.
    • This reply was modified 7 years, 7 months ago by Sa?a.
    • This reply was modified 7 years, 7 months ago by Sa?a.
    Thread Starter Andyt8

    (@andyt8)

    Thank you for your answer. All external domains were already added through SlimStat settings.

    The only change was adding your “add_filter-Script” and it worked instantly.

    Thank you very much.

    regards,
    Andyt

    Plugin Author Jason Crouse

    (@coolmann)

    Great, thank you both.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘XMLHttpRequest cannot load wp-admin/admin-ajax.php’ is closed to new replies.