Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SuN-80 opened this issue Jul 26, 2023 · 1 comment

Comments

@SuN-80
Copy link

SuN-80 commented Jul 26, 2023

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.

@dkern
Copy link
Owner

dkern commented Sep 7, 2023

Hi. What exactly is the problem? Are there any errors? What have you debugged so far? Some more details would be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants