• Hi,

    Love the plugin but I’m having a problem when using quizzes in ajax mode.

    I’m using the code below to load jQuery and other js scripts in the footer, rather than the header:

    wp_deregister_script('jquery');
    wp_register_script('jquery', '/wp-includes/js/jquery/jquery.js', false, false, true);
    wp_enqueue_script('jquery');

    With that code running, I get this console error when clicking Show Results:

    Uncaught TypeError: Cannot read property 'length' of undefined

    Disabling the code above makes Watu work fine.

    Am I right in thinking this is happening because the Watu JS in the head isn’t using $( document ).ready()?

    If that’s correct, how can I add this? Thank you.

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Bob

    (@prasunsen)

    It uses document.ready(). What exactly is on the line where you get the error?
    Posting the URL here will be useful.

    Thread Starter GeniusStartup

    (@geniusstartup)

    Thanks for the quick reply.

    The console error refers to line 165, which starts:

    for(x=0; x<Watu.qArr.length; x++) {

    Just noticed there’s also another error:

    Uncaught ReferenceError: jQuery is not defined

    being triggered by this part of the source code:

    var watuURL='';
    jQuery(function($){
    question_ids = "4,5";
    exam_id = 2;

    Sorry, I can’t post a live link because the page is still being developed.

    Plugin Author Bob

    (@prasunsen)

    As you see, moving jQuery at the bottom makes even document.ready not work. So you should not do it. Keep jQuery at top, many plugins rely on it.

    Thread Starter GeniusStartup

    (@geniusstartup)

    All other plugins work fine. Loading jQuery in the footer is common for speed optimization.

    The bit of code causing the error isn’t using document.ready, it’s using

    jQuery(function($){

    Plugin Author Bob

    (@prasunsen)

    The fact that your other current plugins run fine does not mean that other plugins that you will install in the future will run fine.

    jQuery(function($)) is jQuery’s equivalent to document.ready. We have no plans for changing it for the moment so if you want to use Watu you’ll need to keep jQuery in the head.

    Plugin Author Bob

    (@prasunsen)

    Here is a discussion about the different document.ready syntaxes, although you can find them in the official jQuery docs as well:

    https://stackoverflow.com/questions/3528509/document-readyfunction-vs-function

    Plugin Author Bob

    (@prasunsen)

    And here’s an example to see exactly how complicated is to use document.ready before including jQuery:

    https://writing.colin-gourlay.com/safely-using-ready-before-including-jquery/

    This is not worth the effort for us just to allow 0.001% to make minor speed optimizations. jQuery must be loaded in the head, which is the standard WP behavior for a good reason.

    Hello
    I think I’m having the same error and I’m not loading jquery in footer.
    I do use asynch tag on some scripts but this doesn’t seem to make a difference (turning it off didn’t bring a difference)

    the JS error I’m getting:

    Uncaught TypeError: Cannot read property 'length' of undefined
        at Object.Watu.submitResult (/wp-content/plugins/watu/script.js:165)

    for(x=0; x<Watu.qArr.length; x++) {

    any ideas what might be causing this?

    Plugin Author Bob

    (@prasunsen)

    Send me live URL to see it.

    Hello
    here is the live link: test

    I will turn off jquery in few hours as I don’t want a broken quiz to be live on the site

    thank you for looking into it

    Plugin Author Bob

    (@prasunsen)

    You have a fatal error on a Cloudflare script, no idea what is it:

    TypeError: a.target.className.indexOf is not a function

    https://ajax.cloudflare.com/cdn-cgi/nexp/dok3v=f2befc48d1/cloudflare.min.js

    It doesn’t work correctly, disable this optimization.

    hi
    thank you for looking it. I think it’s the Rocket Loader? optimization option.
    I turned it off but strangely then other errors popped out, maybe because the cache wasn’t fully cleared
    Will look into it more

    thanks!

    can I just ask how did you find the cloudflare error?
    that would be very useful to know…

    The only thing I see in the Console (inspect element) is:
    A Parser-blocking, cross-origin script, https://ajax.cloudflare.com/cdn-cgi/nexp/dok3v=f2befc48d1/cloudflare.min.js, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.

    thanks a lot!

    Plugin Author Bob

    (@prasunsen)

    I’m, using Firebug console in Firefox. It’s very useful for finding JS errors.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘jQuery error’ is closed to new replies.