Use to ajax for php page
AJAX Code:
ajaxpg.js
?[Copy to clipboard]View Code JAVASCRIPT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | var http_request=false; function send_request(url){ 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){ window.alert("XMLHttp object creation failed"); return false; } http_request.onreadystatechange=processrequest; http_request.open("GET",url,true); http_request.send(null); } function processrequest(){ if(http_request.readyState==4){//Object state if(http_request.status==200){//return Successful document.getElementById(reobj).innerHTML=http_request.responseText; } else{ //Exception Errors alert("Exception Errors!"); } } } function dopage(obj,url){ document.getElementById(obj).innerHTML="Loading..."; send_request(url); reobj=obj; } |
index.php:
I am a content div on the display, when the flip action arises, the use of AJAX to update DIV to achieve the effect of this is the contents page shows the page code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | < ?php header("Content-type: text/html;charset=utf-8"); ?> <html> <head> <script language="javascript" src="ajaxpg.js"></script> </head> <body> <div id="result"> < ?php $page=isset($_GET['page'])?intval($_GET['page']):1; $num=10; $db=mysql_connect("www.easemarry.com","root","root"); mysql_select_db("cr_download"); $result=mysql_query("select * from cr_userinfo"); $total=mysql_num_rows($result); $url='test.php'; $pagenum=ceil($total/$num); $page=min($pagenum,$page); $prepg=$page-1; $nextpg=($page==$pagenum ? 0 : $page+1); $offset=($page-1)*$num; $pagenav=":<B>".($total?($offset+1):0)."-<b>".min($offset+10,$total)."</b>,Total:$total"; if($pagenum< =1) return false; $pagenav.=" <a href=javascript:dopage('result','$url?page=1');> < < </a> "; if($prepg) $pagenav.=" <a href=javascript:dopage('result','$url?page=$prepg');> < </a> "; else $pagenav.=" < "; if($nextpg) $pagenav.=" <a href=javascript:dopage('result','$url?page=$nextpg');> > </a> "; else $pagenav.=" > "; $pagenav.=" <a href=javascript:dopage('result','$url?page=$pagenum');> >> </a> "; $pagenav.=" page,Total page: $pagenum"; If($page>$pagenum){ Echo "Error : Can Not Found The page ".$page; Exit; } $info=mysql_query("select * from cr_userinfo limit $offset,$num"); While($it=mysql_fetch_array($info)){ Echo $it['username']; echo ""; } echo""; echo $pagenav; ?> </div> </body> </html> |
test.php:
The key to flip when the flip is called dopage() function, and then use the callback information to update the content div. The core server-side code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | < ?php header("Content-type: text/html;charset=utf-8"); $page=isset($_GET['page'])?intval($_GET['page']):1; $num=10; $db=mysql_connect("www.easemarry.com","root","root"); mysql_select_db("cr_download"); $result=mysql_query("select * from cr_userinfo"); $total=mysql_num_rows($result); $url='test.php'; $pagenum=ceil($total/$num); $page=min($pagenum,$page); $prepg=$page-1; $nextpg=($page==$pagenum ? 0 : $page+1); $offset=($page-1)*$num; $pagenav=":<B>".($total?($offset+1):0)."-<b>".min($offset+10,$total)."</b>,Total:$total"; if($pagenum< =1) return false; $pagenav.=" <a href=javascript:dopage('result','$url?page=1');> < < </a> "; if($prepg) $pagenav.=" <a href=javascript:dopage('result','$url?page=$prepg');> < </a> "; else $pagenav.=" < "; if($nextpg) $pagenav.=" <a href=javascript:dopage('result','$url?page=$nextpg');> > </a> "; else $pagenav.=" > "; $pagenav.=" <a href=javascript:dopage('result','$url?page=$pagenum');> >> </a> "; $pagenav.=" page,Total page: $pagenum"; If($page>$pagenum){ Echo "Error : Can Not Found The page ".$page; Exit; } $info=mysql_query("select * from cr_userinfo limit $offset,$num"); While($it=mysql_fetch_array($info)){ Echo $it['username']; echo ""; } echo""; echo $pagenav; ?> |
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.


The fact that two individuals may be exactly alike in their outward appearance, yet differ in their inheritance, is so important that an exact differentiation is desirable. ,