在php选择ajax成功之后简单的jquery分页

I want to paginate the result of my ajax success. In my ajax when I get success I append all result into one table (this table is empty by default only header).

I used this tutorial but I can't figure out how to make it work when the table is empty by default. I was able to make it run when there are values by default.

When the table is populated after ajax success nothing is happening to the data all are displayed. Is there a more applicable sample or tutorial for this kind of scenario. Or what needs to be done on the current tutorial to make it work.

Any suggestion is appreciated

You shouldn't use pagination this way, I suggest you to make your function returning only the records needed for the selected page.

It's useles to make your ajax return all the set (ej. 300 rows) if you are only going to show only a subset (ej. 30 rows in page 1). So you should add to the function which return the records from the DB (lets call it getRecords) a few parameters more:

  • page: the current/selected page of the paginator
  • records: how many records you want to show in each page

Combining this two you can limit your sql accordingly, f.instance (you can prepare the limit and the offset before the call in your php code):

select blablabla from blablable where blablablu
limit records, offset (page  * records)

note: the first page here is zero. So for the first page the first record will be 0 and the last record shown will be 30 (this is (0 + 1) *30).

Here you have a good tutorial.