This time I will bring you the paging effect without Ajax refreshing. What are the precautions for achieving the paging effect without Ajax refreshing? The following is a practical case, let's take a look.
Ajax has no refresh paging effect, the following code implements it
nbsp;html> <meta> <title>Ajax无刷新分页效果</title> <script> function showpage(url) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { document.getElementById("result").innerHTML = xhr.responseText; } } xhr.open('get',url); xhr.send(null); } window.onload = function () { showpage('page.php'); } </script> <h2 id="Ajax无刷新分页效果">Ajax无刷新分页效果</h2> <p></p>
The paging code found online, can be used for personal testing~
/* * Created on 2011-07-28 * Author : LKK , http://lianq.net * 使用方法: require_once('mypage.php'); $result=mysql_query("select * from mytable", $myconn); $total=mysql_num_rows($result); //取得信息总数 pagepide($total,10); //调用分页函数 //数据库操作 $result=mysql_query("select * from mytable limit $sqlfirst,$shownu", $myconn); while($row=mysql_fetch_array($result)){ ...您的操作 } echo $pagecon; //输出分页导航内容 */ //if(!function_exists("pagepide")){ #$total 信息总数 #$shownu 显示数量,默认20 #$url 本页链接 function pagepide($total,$shownu=20,$url=''){ #$page 当前页码 #$sqlfirst mysql数据库起始项 #$pagecon 分页导航内容 global $page,$sqlfirst,$pagecon,$_SERVER; $GLOBALS["shownu"]=$shownu; if(isset($_GET['page'])){ $page=$_GET['page']; }else $page=1; #如果$url使用默认,即空值,则赋值为本页URL if(!$url){ $url=$_SERVER["REQUEST_URI"];} #URL分析 $parse_url=parse_url($url); @$url_query=$parse_url["query"]; //取出在问号?之后内容 if($url_query){ $url_query=preg_replace("/(&?)(page=$page)/","",$url_query); $url = str_replace($parse_url["query"],$url_query,$url); if($url_query){ $url .= "&page"; }else $url .= "page"; }else $url .= "?page"; #页码计算 $lastpg=ceil($total/$shownu); //最后页,总页数 $page=min($lastpg,$page); $prepg=$page-1; //上一页 $nextpg=($page==$lastpg ? 0 : $page+1); //下一页 $sqlfirst=($page-1)*$shownu; #开始分页导航内容 $pagecon = "显示第 ".($total?($sqlfirst+1):0)."-".min($sqlfirst+$shownu,$total)." 条记录,共 <b>$total</b> 条记录"; if($lastpg首页 "; else $pagecon .=" 首页 "; // if($prepg) $pagecon .=" <a>前页</a> "; else $pagecon .=" 前页 "; // if($nextpg) $pagecon .=" <a>后页</a> "; else $pagecon .=" 后页 "; // if($page!=$lastpg) $pagecon.=" <a>尾页</a> "; else $pagecon .=" 尾页 "; if($page!=1) $pagecon .=" <a>首页</a> "; else $pagecon .=" 首页 "; if($prepg) $pagecon .=" <a>前页</a> "; else $pagecon .=" 前页 "; if($nextpg) $pagecon .=" <a>后页</a> "; else $pagecon .=" 后页 "; if($page!=$lastpg) $pagecon.=" <a>尾页</a> "; else $pagecon .=" 尾页 "; #下拉跳转列表,循环列出所有页码 // $pagecon .=" 到第 <select>\n"; $pagecon .=" 到第 <select>\n"; for($i=1;$i$i\n"; else $pagecon .="<option>$i</option>\n"; } $pagecon .="</select> 页,共 $lastpg 页"; return $page; } //}else die('pagepide()同名函数已经存在!');</select>
The following is a simple paging display I made
<?php header("Content-type:text/html; charset=utf-8"); $link = mysqli_connect('localhost','root','123','good'); if (!$link) { die("连接错误: " . mysqli_connect_error()); } $sql = "SELECT * FROM ecs_category"; $qry = mysqli_query($link,$sql); $total = mysqli_num_rows($qry); $per = 10; $page = pagepide($total,$per); $sql = "SELECT cat_id,cat_name FROM category limit $sqlfirst,$shownu"; $result = mysqli_query($link,$sql); //$goods = mysqli_fetch_all($result,MYSQLI_ASSOC); //mysqli_free_result($result); echo <<<eof <style type="text/css"> table{width:500px;margin:auto;border: 1px solid black; border-collapse:collapse;text-align:center;} td{border: 1px solid black;}
序号 | 商品编号 | 商品类型 |
".++$num." | "; echo "$goods[cat_id] | "; echo "$goods[cat_name] | "; echo "
$pagecon |
The page will not be refreshed and the URL will not change. You can see the data interaction of the website
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Ajax+Spring implements file upload
Ajax front-end and back-end interaction method
The above is the detailed content of Ajax achieves paging effect without refreshing. For more information, please follow other related articles on the PHP Chinese website!

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
