Pagination using jquery append
I'm trying to implement twitter style pagination, where the user clicks on 'More', resulting in more content appearing.
Current this works fine, however I don't know how to keep track of the current start_limit and end_limit:
# get more replies:
if (isset($_POST['ajax']) && $_POST['ajax'] == 'Reply')
{
# yes these will be checked:
$thread_id = $_POST['id'];
$start_limit = $_POST['start_limit'];
$end_limit = $_POST['end_limit'];
$ajax_auth_token = $_POST['ajax_auth_token'];
# return doesn't work?'
开发者_如何学Go print_r(sql_get_replies_by_thread_id($link, $thread_id, $start_limit, $end_limit));
}
The above code basically performs a SQL statement which uses LIMIT $start_limit, $end_limit
This is sent via this code, at the moment I just display the output in an alert box, I know you can use jquery append for the returned HTML:
<script type="text/javascript">
$(document).ready(function() {
$('.more_replies').live("click",function() {
$.post("http://localhost/forum_site/?action=ajax", {id: "40", ajax: "Reply", start_limit: "0", end_limit: "3", ajax_auth_token: "Something" },
function(data) {
alert("Data Loaded: " + data);
});
});
});
</script>
So the limit will be 0 and 3 (LIMIT 0,3).
How can I get these values from a link e.g. <a href="/view.php?ajax_auth_token=a&id=x&start_limit=y&end_limit=z">More</a>
When the user clicks on this link start_limit and end_limit should be incremented by 30.
If you want to keep the variables in the href
attribute then you would have to do some url parsing, reading it extracting the variables and rewriting it. Instead i would suggest you use the jQuery .data()
method http://api.jquery.com/data/ Then you would something like:
//set initial values
$(".more_replies").data("pagination",{start_limit0, end_limit:3});
//then you increment it
var pagination = $(".more_replies").data("pagination");
$(".more_replies").data("pagination",{
start_limit: pagination.start_limit+=30,
end_limit: pagination.end_limit+=30,
});
精彩评论