Php Ajax implements page turning effect

time:14-04-14 forum:PHP tools and code
  http://www.jzxue.com/wangzhankaifa/java... -1030.html

recently in the book of "conquest Ajax", the case inside is used in the background, but I do not understand it myself, As for PHP, I decided to rewrite the background I saw in PHP. This is the first example inside, the twelfth chapter of server side programming example, relatively simple. The

1. system describes

now assuming that the page is a message page is all the messages, the results only show the title, and provide the function of keyword query by the title. The database is page_turning, the message table info has four fields, ID, title, content, date.

the functions to be implemented include:

A: using Ajax to asynchronously get a page data, so as to achieve no refresh display.

b: provides query function and can also have paging effect on query results.

2. client design

a: page structure

interface consists of two parts, one is a form for query, one is a table structure for displaying results, such as

in this section of code, form1 is used to ask the user to enter keywords for query,.Lt in the form; s Pan.gt; mark is used to prompt that the user is communicating with the server; the clicking event of the query button is set to.Quot; getPage (1).Quot; that is, getting the data on the first page.

b: the purpose of designing Ajax logic

Ajax logic is to initiate asynchronous requests to the server side, and to display the result of the request to the page, to generate a table form from the server side directly from the server side, and to directly add it to the content container (.Lt; div id='content'.gt;) at the client side;

code:

[code]var content = document.getElementById ('content');
var tip = document.getElementById ('tip'); The function of the connection function is to send the Ajax request, the show function is the callback function, the content returns to the
connection ('show.php?.amp; page='page'.amp; key=').
{
content.innerHTML = '=';
tip.style.display ='none';
content.innerHTML = text;

}
showContent (ID) function, according to the message ID, show the contents of the message. The

3. server side design

page is show.php, which accepts key, page parameters from the client, and determines the message to display according to the keyword and the page number that needs to be displayed. If the display is not the first page, there is no first page in the column of the bottom page number, otherwise, if it is not the last page, there is no next page in the bottom column of the bottom page.

specific content:

[code].lt;? Php
pageSize = 10;
key = _GET.#91;'key'.#93; / / / / keyword

query =.Quot;

pageNum = floor (counts/pageSize) 1; / / how many pages

strHTML = '; / / / / / / HTML statement to be inserted in
strHTML. =.Quot. Ke'%key%'limit numInfront, pageSize.quot;
result1 = mysql_query (query1) or die. .quot;
while (item = mysql_fetch_row)
{
strHTML. RHTML =.Quot;.Lt; /tbody.gt;.Lt; /table.gt;.Quot;

strHTML. ='.lt; br.gt; />strHTML = ` first pages'; A href='javascript:getPage (.Quot;.I..Quot;) 'title =' I page'.gt;.#91; i.#93;.Lt; /a.gt;.Quot;

}
mysql_close ();
.Gt;


below are encapsulated connection functions. />xmlHttp = new ActiveXObject (.Quot; Microsoft.XMLHTTP.quot; Microsoft.XMLHTTP.quot);
}catch (E)
{
xmlHttp = false. N connection (URL, fun, style)
{
//alert (fun);
var xmlHttp =; .responseText;
}
else if (style =.Quot; XML.quot;)
{
xmlDoc = xmlHttp.responseXML. Br />}[/code]

prev:HTML page automatic loading method next:Ji'nan second-hand housing listing avera...
post comment
Notice



approved   Wearing 35 yuan clothes and feeding ...   The age of mortgage repayment is rai...   What do you do with a baby crying ou...   39 years old as a girl! Takizawa Mak...   Have you ever eaten steamed pagoda f...
rand   MYSQL query optimization   PHP completely filters HTML, JS, CSS...   PHP extraction of Chinese characters...   Code to crack burglar chain by forgi...   Error syntax error, unexpected T_ENC...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com