• Hello,

    with WPP v5.2.0 and my WordPress Installation (newest Version) and JQuery 3.4.1, an JavaScript Error is thrown for the AJAX Request, that is generated within your Front.php Code:

    wp_register_script(‘wpp-js’, plugin_dir_url(dirname(dirname(__FILE__))) . ‘assets/js/wpp-5.2.0.min.js’, [], WPP_VERSION, false);
    $params = [
    ‘sampling_active’ => (int) $this->config[‘tools’][‘sampling’][‘active’],
    ‘sampling_rate’ => $this->config[‘tools’][‘sampling’][‘rate’],
    ‘ajax_url’ => esc_url_raw(rest_url(‘wordpress-popular-posts/v1/popular-posts’)),
    ‘ID’ => $is_single,
    ‘token’ => wp_create_nonce(‘wp_rest’),
    ‘lang’ => function_exists(‘PLL’) ? $this->translate->get_current_language() : null,
    ‘debug’ => WP_DEBUG
    ];
    wp_enqueue_script(‘wpp-js’);
    wp_add_inline_script(‘wpp-js’, json_encode($params), ‘before’);

    The JS Error is thrown for the inproper JSON Format for “:”. But the original problem of this seems to be lying within the AJAX handling code, not the JSON block. I’ve already tried to fix that issue by adding surrounding ” (brackets) to each JSON value, but this seems not to be the source of the problem.

    I tried to update my JQuery version to newest 3.5.1 and also to migrate it down to 3.0 or 1.9, without any positive result. I’m sure that your Plugin is working with WordPress Standard JQuery version, but did you tried it with a newer version?

    Thanks for your Plugin, hope that you could help to fix it.

    Best regards,

    Carsten

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @carstenmeiselbach,

    The JS Error is thrown for the inproper JSON Format for “:”. But the original problem of this seems to be lying within the AJAX handling code, not the JSON block.

    Can you please share the exact error message you’re seeing on your console?

    I’m sure that your Plugin is working with WordPress Standard JQuery version, but did you tried it with a newer version?

    WPP doesn’t use jQuery at all so that’s not really the issue.

    Thread Starter Carsten Meiselbach

    (@carstenmeiselbach)

    Hi Héctor,
    thanks for your fast feedback.

    Error thrown is this:
    Uncaught SyntaxError: Unexpected token ‘:’

    Testet with Chrome and FF newest Version.

    Testpage for you: https://happycarb.de/kontakt/

    Good to know that your Plugin doesn’t need JQuery. I’m curious what might be the source of the problem here.

    Best regards,

    Carsten

    Plugin Author Hector Cabrera

    (@hcabrera)

    Checked that URL Carsten but it doesn’t seem that WPP is active now. At least I don’t see any WPP related code in that page.

    Thread Starter Carsten Meiselbach

    (@carstenmeiselbach)

    Sorry, I need to deactivate your Plugin again since it makes to much Side effects on my Website but I reactivated it now again.

    Please give it a quick check on my named testpage.

    Cheers.

    Plugin Author Hector Cabrera

    (@hcabrera)

    It seems to be a compatibility issue with the Fast Velocity Minify plugin. FVM is removing an inline script needed by WPP to be able to do its thing.

    For the time being, let’s have FVM ignore WPP’s scripts so the plugin can work again on your site:

    1. Go to Settings > Fast Velocity Minify and click on the Pro tab.
    2. Under Ignore List, add: /wordpress-popular-posts/assets/js/, then scroll down to the bottom of the page and click on Save Changes.
    3. Click on the Status tab.
    4. Click the Delete button under Purge the cache files

    Please report back your results.

    Thread Starter Carsten Meiselbach

    (@carstenmeiselbach)

    Hello & thanks for your quick help. I’ve add the Plugin Asset Path to the ignore list of FVM and it worked again.

    Could you tell me what inline code is exactly removed by FVM? Maybe I could add this manually to my global JS that FVM could work again without the ignored path.

    Best regards,

    Carsten

    Plugin Author Hector Cabrera

    (@hcabrera)

    This line injects a <script> tag that contains a JSON object with some variables into your site’s header. Then the plugin adds the application/json attribute and an ID attribute to said script here so WPP’s script can find it later when its JS file is loaded by the browser.

    It seems that FVM is inserting this inline application/json script (all inline scripts actually) into the minified JS file. The browser then sees the bare JSON string inside a try {...} catch {...} blocks, doesn’t understand what that is and triggers the error you were seeing earlier.

    If there’s a way to tell FVM to leave the inline application/json script alone then it might be possible to remove WPP’s script from the Ignore list and the plugin theoretically should work as usual.

    I will try and see if I can find to circumvent that as I sure other JS minification plugins may be also affected by this issue. The solution I posted above is just a temporary workaround (although I’m not really sure that JS minification plugins should be messing with application/json scripts in the first place.)

    Thanks for the donation by the way. That was very kind of you!

    Plugin Author Hector Cabrera

    (@hcabrera)

    Thread Starter Carsten Meiselbach

    (@carstenmeiselbach)

    Hello Héctor,

    big thanks that you involved the FVM Plugin Author here.
    So we’re looking forward what could be done here.

    Best regards,
    Carsten

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘JavaScript AJAX / JSON Issue with WPP v5.2.0’ is closed to new replies.