PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Ajax does not load image

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi, I am trying to use the WooCommerce shop with pagination and an AJAX-based filter. The problem is that when navigating through the pages, the product images do not display. I tried inserting a script via the advanced settings module to disable lazy loading, but it didn't work (I tested these two different solutions):

jQuery(document).trigger('jetpack-lazy-images-load');

jQuery(window).trigger('scroll');

I am using WP Fastest Cache for caching.

Can you help me? Thanks in advance.

Piero

Hello Piero

Thank you for the details.

First, why your two attempts could not work. Jetpack listens for that event with a native document.addEventListener, and jQuery's trigger does not create a native DOM event, it only notifies handlers registered through jQuery. So the Jetpack handler was never called. The correct form is:

document.dispatchEvent( new CustomEvent('jetpack-lazy-images-load') );

The scroll trigger fails for the same kind of reason. Most lazy loaders today use IntersectionObserver and observe only the images that existed when they started, so a scroll event does not make them pick up images added later by AJAX.

Second, what we think is happening. Your lazy loading script replaces the image src with a placeholder and keeps the real address in a data attribute. It processes only the images present in the page when it initialises. When you paginate, our plugin replaces the product block with new HTML, that script never runs over it, and the new images stay as placeholders. That is why they appear blank.

Which script it is matters, because each one needs a different call. You mention WP Fastest Cache, and its premium version has its own lazy load which marks images with attributes like data-wpfc-original-src. In that case the Jetpack event is irrelevant. It could also be Jetpack, your theme, or a separate lazy load plugin.

So please send us:

  1. The link to your shop page, so we can look at it ourselves.
  2. The HTML of one product image after you switch to page 2. Right click the blank image, choose Inspect, and copy the whole img tag with all its attributes. The attribute names tell us immediately which script is involved.
  3. Which plugin handles lazy loading on your site, and whether the lazy load option is enabled in WP Fastest Cache.

In the meantime, there is a general workaround you can try. Our plugin has a field for JavaScript that runs after every AJAX redraw, in the advanced settings, which is where you already placed your code. Put this there instead:

    jQuery('.products img').each(function () {
        var img = jQuery(this);
        var real = img.attr('data-wpfc-original-src') || img.attr('data-lazy-src') || img.attr('data-src');
        if (real) {
            img.attr('src', real);
            var realset = img.attr('data-wpfc-original-srcset') || img.attr('data-lazy-srcset') || img.attr('data-srcset');
            if (realset) {
                img.attr('srcset', realset);
            }
            img.removeClass('lazy lazyload jetpack-lazy-image');
        }
    });

 

This takes the real address out of whatever data attribute your lazy loader used and puts it back into src, so the images load regardless of which script produced them. It disables lazy loading for products loaded by AJAX, which is a reasonable trade for a filtered listing.

Best regards
Alex