Php+ajax Implementing a No-refresh paging method, Ajax paging _php tutorial

Source: Internet
Author: User

Php+ajax Implementing a No-refresh paging method, Ajax paging


The example in this paper describes the method of Php+ajax to implement no-refresh paging. Share to everyone for your reference. The implementation method is as follows:

This is a +js based on the original ecological php +ajax instance of the page, we detailed from the database creation to js,php,html page creation to show you how to implement Ajax paging data method.

The steps are as follows:

First, create a database

The SQL statements are as follows:

Copy the Code code as follows: CREATE TABLE ' Tb_user ' (
' id ' int (ten) is not NULL auto_increment,
' username ' varchar (not NULL),
PRIMARY KEY (' id ')
) Engine=myisam DEFAULT Charset=utf8 auto_increment=10;

INSERT into ' Tb_user ' VALUES (1, ' AAA ');
INSERT into ' Tb_user ' VALUES (2, ' BBB ');
INSERT into ' Tb_user ' VALUES (3, ' CCC ');
INSERT into ' Tb_user ' VALUES (4, ' ddd ');
INSERT into ' Tb_user ' VALUES (5, ' Eee ');
INSERT into ' Tb_user ' VALUES (6, ' FFF ');
INSERT into ' Tb_user ' VALUES (7, ' GGG ');
INSERT into ' Tb_user ' VALUES (8, ' hhh ');
INSERT into ' Tb_user ' VALUES (9, ');

Second, the Ajaxpage.js file code is as follows:

Copy CodeThe code is as follows: Var http_request=false;
function send_request (URL) {//Initialize, specify handler function, send request functions
Http_request=false;
Start initializing the XMLHttpRequest object
if (window. XMLHttpRequest) {//mozilla browser
Http_request=new XMLHttpRequest ();
if (http_request.overridemimetype) {//Set MIME category
Http_request.overridemimetype ("Text/xml");
}
}
else if (window. ActiveXObject) {//ie browser
try{
Http_request=new ActiveXObject ("msxml2.xmlhttp");
}catch (e) {
try{
Http_request=new ActiveXObject ("Microsoft.XMLHTTP");
}catch (e) {}
}
}
if (!http_request) {///exception, creation of object instance failed
Window.alert ("Failed to create XMLHTTP Object! ");
return false;
}
Http_request.onreadystatechange=processrequest;
Determine how to send the request, URL, and whether to synchronize execution of the next snippet of code
Http_request.open ("GET", url,true);
Http_request.send (NULL);
}
function to process return information
function ProcessRequest () {
if (http_request.readystate==4) {//Judging object state
if (http_request.status==200) {//information has been successfully returned to start processing information
document.getElementById (reobj). Innerhtml=http_request.responsetext;
}
else{//page is not working
Alert ("The page you requested is not working!") ");
}
}
}
function Dopage (obj,url) {
document.getElementById (obj). innerhtml= "reading data ...";
Reobj = obj;
Send_request (URL);
}
Third, the code of the PHP call is as follows:

Copy CodeThe code is as follows:<title>Php+ajax Pagination Demo</title>



<?php
$terry =mysql_connect ("localhost", "root", "") or Die ("Connection Database failed:". Mysql_error ());
mysql_select_db ("Ajaxtest", $terry);
mysql_query ("Set NAMES ' UTF8 '");
$result =mysql_query ("SELECT * from Tb_user");
$total =mysql_num_rows ($result) or Die (Mysql_error ());
$page =isset ($_get[' page ')? Intval ($_get[' page ')): 1;
$page _size=3;
$url = ' index.php ';
$pagenum =ceil ($total/$page _size);
$page =min ($pagenum, $page);
$prepage = $page-1;
$nextpage = ($page = = $pagenum? 0: $page + 1);
$pageset = ($page-1) * $page _size;
$pagenav = ";
$pagenav. = "Show section". ($total? ($pageset + 1): 0). " -". Min ($pageset +5, $total)." Record Total". $total."Record is now the first". $page."Page ";
if ($page <=1)
$pagenav. = "Home";
Else
$pagenav. = "Home";
if ($prepage)
$pagenav. = "Previous page";
Else
$pagenav. = "Previous page";
if ($nextpage)
$pagenav. = "Next page";
Else
$pagenav. = "Next page";
if ($pagenum)
$pagenav. = "Last";
Else
$pagenav. = "Last";
$pagenav. = "Total". $pagenum. " Page ";
if ($page > $pagenum) {
echo "Error: no this page". $page;
Exit ();
}
?>

















<?php$info=mysql_query ("SELECT * from Tb_user ORDER BY id desc-Limit $pageset, $page _size"); while ($array =mysql_fetch_ Array ($info)) {?> <?php}?>
User name User password
<?php echo $array [' id '];? > <?php echo $array [' username '];? >

<?php
echo "

$pagenav

";
?>

I hope this article is helpful to everyone's PHP programming.


Why do I use Php+ajax to implement no-refresh paging, but the Select All button fails? How to Solve

The onchange event of the Select All button is to get to the list data through Ajax, plus the onchange event, here is the checkbox can get to the table, the page directly call JS, has been out of scope, JS is not to get to the list of checkboxes.

Who's to tell me the ajax+php no refresh paging principle

Ajax is a JS script. or using Ajax inside jquery.
If you want to verify the user name. You can add the Onchange= "Invoke function" to your input attribute.
Calling a function is the code of AJAX.
Ajax is the way to get the job done,
First send a request to the page you specified such as abc.php (with your set of post or get),
After the abc.php responds successfully, execute the code inside it to handle the arguments you passed. If this user exists. It then returns a value or function that returns a value or function if it does not exist, and you have to set it yourself.
Ajax then processes the returned value or function, such as displaying it, or invoking the function to disable the Submit button.

http://www.bkjia.com/PHPjc/906121.html www.bkjia.com true http://www.bkjia.com/PHPjc/906121.html techarticle Php+ajax Implementation of the method of no refresh paging, Ajax pagination This article describes the Php+ajax implementation of the method of no refresh paging. Share to everyone for your reference. The implementation method is as follows: This is a ...

  • 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.