jquery.lazy
jquery.lazy copied to clipboard
Custom loader using Ajax fails (not even fired), while lazyloading images work.
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.
Hi. What exactly is the problem? Are there any errors? What have you debugged so far? Some more details would be good.