Implementation of ajax without refreshing pagination (php)

Source: Internet
Author: User

Copy codeThe Code is as follows: <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Title> voting result </title>
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8"/>
<Script type = "text/javascript">
Function GetXmlHttpObject ()
{
Var xmlHttp = null;
Try
{
// Firefox, Opera 8.0 +, Safari
XmlHttp = new XMLHttpRequest ();
}
Catch (e)
{
// Internet Explorer
Try
{
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP ");
}
Catch (e)
{
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
}
Return xmlHttp;
}
Function checkajax (){
XmlHttp = GetXmlHttpObject ()
If (xmlHttp = null)
{
Alert ("your browser does not support AJAX! ");
Return;
} Else
{
Return xmlHttp;
}
}
Function preshow (){
Ajaxobj = checkajax ();
Var url = "page. php? Page = 1 ";
Ajaxobj. onreadystatechange = stateChanged;
Ajaxobj. open ("GET", url, true );
Ajaxobj. send (null );
}
Function showHint1 (str)
{
Ajaxobj = checkajax ();
Document. getElementById ("msg"). innerHTML = "reading data ...... ";
Var url = str;
Ajaxobj. onreadystatechange = stateChanged;
Ajaxobj. open ("GET", url, true );
Ajaxobj. send (null );
}
Function showHint2 (str)
{
Ajaxobj = checkajax ();
Document. getElementById ("msg"). innerHTML = "reading data ...... ";
Var url = str;
Ajaxobj. onreadystatechange = stateChanged;
Ajaxobj. open ("GET", url, true );
Ajaxobj. send (null );
}
Function showHint3 (str)
{
Ajaxobj = checkajax ();
Document. getElementById ("msg"). innerHTML = "reading data ...... ";
Var url = str;
Ajaxobj. onreadystatechange = stateChanged;
Ajaxobj. open ("GET", url, true );
Ajaxobj. send (null );
}
Function showHint4 (str)
{Document. getElementById ("msg"). style. display = "none ";
Ajaxobj = checkajax ();
Document. getElementById ("msg"). innerHTML = "reading data ...... ";
Var url = str;
Ajaxobj. onreadystatechange = stateChanged;
Ajaxobj. open ("GET", url, true );
Ajaxobj. send (null );
}
Function stateChanged ()
{
If (xmlHttp. readyState = 4)
{
Document. getElementById ("message"). innerHTML = xmlHttp. responseText;
}
}
</Script>
</Head>
<Body onload = "preshow ()">
<Div id = "wrapper">
<H4> the user's message is as follows:
<Div id = "message">
</Div>
</Div>
</Body>
</Html>

Copy codeThe Code is as follows: <? Php
$ Link = mysql_connect ('localhost', 'root', '') or die (mysql_error ());
Mysql_select_db ('vote', $ link) or die (mysql_error ());
Mysql_query ("set names utf8 ");
$ Num = 3;
$ Url = "page. php ";
$ Con = "<ul id = 'msg '> ";
$ Page = (isset ($ _ REQUEST ['page'])? $ _ REQUEST ['page']: 1;
$ Offset = ($ page-1) * $ num;
$ Result = mysql_query ("select count (*) FROM client ");
$ Total = mysql_fetch_row ($ result );
$ Total = $ total [0];
$ Pagenum = ceil ($ total/$ num );
$ Page = min ($ pagenum, $ page); // get the homepage
$ Prepg = $ page-1; // Previous page
If ($ prepg <= 1)
$ Prepg = 1;
$ Nextpg = ($ page = $ pagenum? 1: $ page + 1); // next page
// If there is only one page, the function will jump out:
If ($ pagenum <= 1)
Return false;
$ SQL = "SELECT 'name', 'content' FROM 'client' LIMIT". $ offset. ",". $ num;
$ Res = mysql_query ($ SQL );
While ($ content = mysql_fetch_row ($ res )){
$ Con. = "<li> <span> $ content [0]: </span> $ content [1] </li> ";
}
$ Con. = "</ul> ";
$ Con. = <PAGE
<P id = "page"> <a href = "#" id = "first" onclick = "showHint1 ('$ url? Page = 1') "> homepage </a> | <a href =" # "id =" pre "onclick =" showHint2 ('$ url? Page = $ prepg ') "> previous page </a> | <a href =" # "id =" next "onclick =" showHint3 (' $ url? Page = $ nextpg ') "> next page </a> | <a href =" # "id =" last "onclick =" showHint4 (' $ url? Page = $ pagenum ') "> last page </a> </p>
PAGE;
Echo $ con;
?>

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.