Implementation of Ajax without refreshing paging instance code and ajax paging instance code

Source: Internet
Author: User
Tags zts

Implementation of Ajax without refreshing paging instance code and ajax paging instance code

Today we are going to use ajax to make a page:

Implement Ajax paging:

If possible, add the query conditions.

  1. Find a table for paging
  2. Pagination does not use the page class
  3. Page does not need to be refreshed
  4. Load data using Ajax
<! Doctype html> 

Above is the page: test. php

<? Phpinclude ("DBDA. class. php "); $ db = new DBDA (); // pass the two values of the previous page to $ page = $ _ POST [" page "]; // $ key = $ _ POST ["key"] on the current page; // condition, keyword $ num = 20; // defines the number of data entries on a page, $ tiaoshu = ($ page-1) * $ num; // how many records are skipped by $ tiaoshu ($ page-1) * $ num now $ num is 20 // write $ SQL statement $ SQL = "select * from chinastates where areaname like '% {$ key} % 'limit {$ tiaoshu }, {$ num} "; // query like '% {$ tiaojian} %' based on the keyword '. Echo $ db-> JSONQuery ($ SQL );

The above is the processing page: chuli. php:

<?phpinclude("DBDA.class.php");$db = new DBDA();$key = $_POST["key"];$num = 20;$sql = "select count(*) from chinastates where areaname like '%{$key}%'";$zts = $db->StrQuery($sql);echo ceil($zts/$num);

The above is a paging page: fenye. php

The following figure shows the display effect:

As you click the next page, five pages are displayed, and two pages are displayed on both the left and right sides of the current page. You can adjust the number of information displayed on each page.

Enter keywords in the text box above to display relevant information. This is the page we use ajax to do.

The above is the Ajax Implementation of the example code for refreshing pagination. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.