No refreshing pages in ajax, supporting id locating

Source: Internet
Author: User

<? Php
Header ("Content-Type: text/html; charset = UTF-8 ");
// AK, QQ: 42220796
// Total number of single-page items the url address after the current page is clicked get the js function of the application displays several display addresses
Function AjaxPage ($ Total, $ ListNub, $ CurrentPage, $ Url, $ AjaxAction, $ HalfPer =, $ ViewId =)
{
// Calculate the total number of pages
$ TotalPage = @ ceil ($ Total/$ ListNub );
$ Total = $ totalPage-1;
$ Re = "";

// Echo $ CurrentPage;
$ Re. = ($ CurrentPage> 0)
?
"<Td> <
Href = "javascript: $ AjaxAction ($ Url = 0, $ ViewId)" "> homepage </a> </td> <
Href = "javascript: $ AjaxAction (". $ Url. "=". ($ CurrentPage-1). ", $ ViewId)" "> previous page </a> </td>"
:
"<Td> homepage </td> <td> previous page </td> ";
For ($ I =
$ CurrentPage-$ HalfPer, $ I> 0 | $ I = 0, $ j =
$ CurrentPage + $ HalfPer, $ j <$ totalPage | $ j = $ totalPage; $ I <$ j; $ I ++
)
{
$ Re. = $ I ==$ CurrentPage
?
"<Td> <B class = currentPage> [". ($ I + 1 ).
"] </B> </td>"
: "<Td> <
Href = "javascript: $ AjaxAction ($ Url = $ I, $ ViewId)"> ". ($ I + 1 ).
"</A> </td> ";
}
$ Re. = ($ CurrentPage <$ total
)
? "<Td> <
Href = "javascript: $ AjaxAction (". $ Url. "= ". ($ CurrentPage + 1 ). ", $ ViewId)" "> next page </a> </td> <
Href = "javascript: $ AjaxAction (". $ Url. "= ". ($ total ). ", $ ViewId)" "> last page </a> </td>"
:
"<Td> next page </td> <td> last page </td> ";
$ Re = "<table
Style = text-align: center> <tr> $ re </tr> </table> ";
Return
$ Re;

}
// The total number of pages, passed page variable-the number of pages before and after the current page url address
$ Page = $ _ GET [page];
// Echo
Page (10, $ page, index. php? Page, 2 );


?>

<Div id = "nike">
<? Php
Echo
AjaxPage (, $ page, rand. php? Page, ajaxaction, 2, nike );
?>
</Div>


<Script type = "text/javascript" language = "javascript">
Var
Http_request = false;

Function send_request (url, htmlid ){
Http_request =
False;
If (window. XMLHttpRequest ){
Http_request = new
XMLHttpRequest ();
If (http_request.overrideMimeType)
{
Http_request.overrideMimeType (text/xml );
}
}
Else if (window. ActiveXObject ){
Try
{
Http_request = new
ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e)
{
Try {
Http_request = new
ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e)
{}
}
}
If (! Http_request)
{
Alert (the XMLHttpRequest object cannot be created !);
Return
False;
}
Http_request.onreadystatechange = function
() {Likeakak (htmlid);} // processRequest (htmlid)
Http_request.open (GET,
Url, true );
Http_request.send (null );

}

// Process the returned information
Function processRequest (htmlid ){
If
(Http_request.readyState = 1)
{
Document. getElementById (htmlid). innerHTML = "downloading ...";
}
If
(Http_request.readyState = 4 ){
If (http_request.status = 200)
{
Document. getElementById (htmlid). innerHTML = http_request.responseText;
}
Else
{
Alert (request exception );
}
}
}
// Process the returned information
Function
Likeakak (htmlid)
{
If (http_request.readyState = 1)
{
Document. getElementById (htmlid). innerHTML = "downloading ...";
}
If
(Http_request.readyState = 4 ){
If (http_request.status = 200)
{
Document. getElementById (htmlid). innerHTML = http_request.responseText;
}
Else
{
Alert (request exception );
}
}
}
Function
Ajaxaction (url, viewid)
{
Send_request (url, viewid );
}

// Customize the call Function
Function elist (id)
{
Var inputarray = new
Array ();

Inputarray [1] = aaa;
Inputarray [2] =
Bbb;
Inputarray [3] = ccc;
Inputarray [4] =
Ddd;
Inputarray [5] = eee;

Send_request (ajax. php? Do = ajax & sort = + id, inputarray [id]);

}

</Script>

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.