Skip to content

Custom loader using Ajax fails (not even fired), while lazyloading images work. #269

@SuN-80

Description

@SuN-80

Hi,
I use this plugin to lazyload images and scripts, and it works well.
But for some reason, it doesn't when I create a custom ajax loader.

This is my code:

$(function() {
	$('img.lazy').lazy({ effect: "fadeIn", effectTime: 1000 }); // works

	$('span.status').lazy({ // this does not works
		threshold: 0,
		checkstatus: function(el, response)  {
			$.ajax({
				url: '/ajax/check',
				method: 'POST',
				dataType: 'json',
				data: { id: $(el).data('id') },
				success: function(data) {
					if(data.valid== true)
						el.append(data.label).addClass('valid').hide().fadeIn('fast');
						
					response(true);
				},
				error: function() {
					console.log("oops.");
					response(false);
				}
			});
		}
   });
});

And here is the html:

<a href="/link">
        <span class="status" data-id="17" data-loader="checkstatus"></span>
         <img class="lazy" src="/img_load.png" data-src="/img/img.jpg" >
</a>

Any idea what's going wrong? Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions