• Resolved BrianRayA

    (@brianraya)


    Dear Support.

    I am running one mc4wp form on my site in 3 different languages. English, German and Dutch. When you try to subscribe to the newsletter on the Dutch and German site the loading symbol/splash keeps on spinning and nothing happens, but when you try to subscribe to the English version everything works well.

    I’ve compared the codes of the forms and they all the same except the descriptions and titels are in the language of the site (DE/ENG/NL).

    When I run console on the .DE or .NL site it gives me this:

    XMLHttpRequest cannot load https://MYSITEURL.com/wp-admin/admin-ajax.php?mc4wp_action=subscribe. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://MYSITEURL.nl' is therefore not allowed access.
    ajax-forms.min.js:1 Object {readyState: 0, responseText: "", status: 0, statusText: "error"}

    I find it strange that it suddenly doesn’t work after updating to 4.2.3.

    Thanks in advance!

    Brian

    https://www.ads-software.com/plugins/mailchimp-for-wp/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Danny van Kooten

    (@dvankooten)

    Hi Brian,

    The error is because, for some reason, your English site seems to be on another domain than your Dutch or German sites. The Dutch and German site will try to submit the form to your English site, which refuses it because by default, scripts can not submit to other forms (because of a security measure).

    Do you have your languages split out over subdomains, by any chance? If these differing site URL’s are intentional, there are two ways to workaround this issue.

    1) In your server configuration, you can specify which URL’s are allowed to submit scripts to your site. You can do this by setting the Access-Control-Allow-Origin header.

    You can do this by adding the following code snippet to your theme its functions.php (or to a plugin of its own).

    if( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
    	$allowed_origins = array(
    		'https://site.com',
    		'https://ge.site.com',
    		'https://nl.site.com'
    	);
    	$origin = ( isset( $_SERVER['HTTP_ORIGIN'] ) ) ? $_SERVER['HTTP_ORIGIN'] : '';
    
    	if( in_array( $origin, $allowed_origins ) ) {
    		// tell server origin is allowed
    		header("Access-Control-Allow-Origin: " . $origin );
    	}
    }

    What it does is that it will check the script origin against a list of your allowed origins, and then tell the server to accept script submissions from all those sites.

    2) Disabling AJAX in your form-settings should fix the issue as well. This is not optional, of course.

    A little technical perhaps, but I hope this helps. Unfortunately this is not a straight plugin issue but rather a server configuration thing, you’d run into the same thing with other plugins submitting AJAX requests from your Dutch or German sites.

    Let me know if I can be of more help!

    Thread Starter BrianRayA

    (@brianraya)

    Thanks for your reply but something went horribly wrong when I added your written code in the Functions.PHP Everything is gone. I can’t even get on WordPress anymore.

    I interpreted your code like this
    if( defined( ‘DOING_AJAX’ ) && DOING_AJAX ) {
    $allowed_origins = array(
    https://MYSITEURL.com’,
    https://https://MYSITEURL.de’,
    https://MYSITEURL.nl’
    );
    $origin = ( isset( $_SERVER[‘HTTP_ORIGIN’] ) ) ? $_SERVER[‘HTTP_ORIGIN’] : ”;

    if( in_array( $origin, $allowed_origins ) ) {
    // tell server origin is allowed
    header(“Access-Control-Allow-Origin: ” . $origin );
    }`
    }`

    Could you tell me what happend cause im clueless and it broke everything.

    Plugin Contributor Harish Chouhan

    (@hchouhan)

    Hello Brian,

    We apologize for the late reply. Can you please let us know if you are still facing this issue?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Subscribe button keeps on loading.’ is closed to new replies.