Created
October 22, 2018 07:51
-
-
Save chillybin/1960888e23029e0c7298073b2a521ec6 to your computer and use it in GitHub Desktop.
Ajax Load More
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("a.load-more").click(function(e){ | |
loadArticle(); | |
e.preventDefault(); | |
}); | |
function loadArticle() { | |
$("footer.infinite a").html("..."); | |
var offset = $("a.load-more").data("count"); | |
var num = parseInt(offset, 10); | |
var cat = $("a.load-more").data('cat'); | |
var loading = $("a.load-more").data('loading'); | |
if(loading == 0){ | |
$("footer.infinite a").data('loading',"1"); | |
$.ajax({ | |
url: "//" + location.host + "/wp-admin/admin-ajax.php", | |
type:'POST', | |
data: { | |
action: 'infinitescroll', | |
offset: num, | |
category: cat | |
}, | |
success: function(html){ | |
var off = $("a.load-more).data('count'); | |
off = parseInt(off, 10) + 5; | |
$("a.load-more").data('loading',"0"); | |
if(html == ''){ | |
$("a.load-more").html('done'); | |
} | |
else { | |
$("a.load-more").before(html); | |
$("a.load-more").data("count", off); | |
$("a.load-more").html("more"); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment