Created
March 26, 2017 16:41
-
-
Save maynagashev/bfce700fa62c3ad95fb9be8f6cbf0bc5 to your computer and use it in GitHub Desktop.
Load more jquery function
This file contains 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
<div class="wrapper tiles"> | |
@foreach($articles as $d) | |
{{$d->title}} | |
<input type="hidden" class="article-id" name="article-id" value="{{$d->id}"> | |
@endforeach | |
</div> |
This file contains 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
// Load more articles | |
$(document).ready(function(){ | |
var category_id = 1; | |
$btn = $('#load-more-articles'); | |
function load() { | |
$.get("/api/articles/more", { category_id: category_id, last_id: $('.article-id').last().val()}) | |
.done(function(r){ | |
$('<div style="display: none;" class="hidden-articles">'+r+'</div>').appendTo('.articles-list'); | |
if (r.match(/item/)) { | |
$btn.show(); | |
} | |
}); | |
} | |
$btn.click(function(e) { | |
$('.hidden-articles').show('slow'); | |
load(); | |
$(this).hide(); | |
return false; | |
}); | |
load(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment