jQuery Pagination Question

2019-09-05 22:47发布

问题:

So I have the following jQuery pagination plugin installed.

http://d-scribe.de/webtools/jquery-pagination/lib/jquery_pagination/README

I understand how to create the pagination navigation, but not quite sure how to implement a new server call everytime a new page is clicked.

Below I've mapped out the steps that I currently have built using PHP and MYSQL.

  1. User searches keyword using HTML form.
  2. jQuery post to PHP process.
  3. PHP gathers 10 records (LIMIT 0,10) and returns to jQuery in JSON format.
  4. jQuery spits out the the first 10 results to a DIV.

Using the pagination plugin I was hoping to adjust the offset whenever a new page is clicked. How do I write a callback function that will allow me to do exactly that?

回答1:

Let's say there are 122 rows and you want to display 20 rows per page. So there are 7 pages. The callback function receives 2 parameters, one of which is the new page index. Let's say the new page index is 5, then the LIMIT statement should be LIMIT(5 * 20, 20).