dkern / jquery.lazy

A lightweight, fast, feature-rich, powerful and highly configurable delayed content, image and background lazy loading plugin for jQuery & Zepto.
http://jquery.eisbehr.de/lazy
Other
1.02k stars 237 forks source link

Intermittent image load with AJAX return #268

Closed offgridforever closed 1 year ago

offgridforever commented 1 year ago

On initial load, all images are lazy. Then when clicking a button to have AJAX fetch the next block of product data, sometimes the images have their data-src rewritten to src and all is well. Sometimes this does not happen. Most of the time, a hard refresh of the page will fix the issue, but not every time.

When it works, it works. If the first fetch works, then any fetches after that work fine. If the first fails, all the rest fail as well.

Code below:

     $(document).ready(function() {
        var instance=$('.lazy').Lazy({
            chainable: false,
            effect: "fadeIn",
            effectTime: 1000,
            threshold: 0
        })
         cstart = 0;
        $(document).on("click",".fsNext", function(){

            $(".fsNext", document).remove();
            cstart = cstart + ipagesize;

           history.pushState("bob", document.title, "viewcategories.asp?idcategory=" + idcategory+"&cstart="+cstart); 
            $.ajax({
                url: 'viewcategoriesfs.asp',
                cache: false,
                type: "get"
            })
            .done(function (data) {
                $(".pcShowProducts").append(data).append(function () {
                    instance.addItems(".lazy");
                    instance.update();
                })
            })
        })
     });