


Detailed explanation of the steps to implement paging technology using ajax (with code)
This time I will bring you a detailed step-by-step explanation of using ajax to implement paging technology (with code). What are the precautions for using ajax to implement paging technology? . Here is a practical case, let’s take a look.
The ajax paging rendering is as follows:
#First, let’s look at the HTML code and CSS code. We need a table and a footer:
<p> </p><p> </p>
日期 | 时间 | 事件 | 报警画面 | 事件备注 |
---|
- 首页
- 上一页
- 下一页
- 最后一页
跳转到 页
The following is the css code:
#global{ position: relative; } #table{ position: absolute; top:19%; left:1.6%; width: 55%; } #table textarea{ width: 10vw; height: 10vh; background-color: transparent; color: #fff; border-width: 0; text-align: center; } table, th, td { border: 0.2px solid rgba(60,166,206,0.2); border-collapse: collapse; color:rgba(60,166,206,1); } th, td { padding: 3px; text-align: center; font-size: 1.6vmin; } td{ background: rgba(2,29,54,1); } th{ background: rgba(20,29,54,1); padding: 1.8% 0; color: rgba(255,255,255,0.8); } #footer{ position: absolute; bottom:5vh; left:7vw; text-align: center; color: rgba(60,166,206,1); } #pagination{ display: inline-block; } #pagination li{ display: inline; } #select{ display: inline-block; margin-left: 40px; } #select input[type="text"]{ width: 30px; height: 20px; background-color: #000; border-width: 1px; } #select input[type="button"]{ width: 40px; height: 23px; background: #000; border:none; } ul li{ cursor: pointer; }
Initialize the start date, end date, number of pages requested, number of pages requested, how many pages of data there are in total, and pass these data to the API provided by the background through ajax Data interface, and then get the data from the database, and then display it on the front end:
var start_date = "2017-01-01", end_date = "2017-01-08"; var pageNo = 1; var pageSize = 4; var pages = 0;
How to get the data of the table and append it to the front end? How to get paginated data and append it to frontend? Use the function we defined below:
loadData(pageNo, pageSize);
Let’s see how this function communicates with the API data interface:
function loadData(pageNo, pageSize){ $(".detail").remove(); //每次重新从 API 数据接口获取数据都要先清除原先表格 `<tr>` 的内容 $.ajax({ url: "/history_alarm", type: "POST", data: JSON.stringify({date:date, page_num:pageNo, page_size:pageSize}), success:function(result){ var results = JSON.parse(result); var list = results.alarm; var totalCount = results.alarm_count; pages = results.page_count; if(list.length != 0){ for(var i=0; i<list.length><p style="text-align: left;">In the loadData function, we have also defined three other functions. Next, let’s look at appendData: </p> <pre class="brush:php;toolbar:false">//注意到我们将 `alarm_id` 作为 `<textarea>` 'class` 的值,也作为提交按钮 `id` 的值,这是因为我们要通过 ajax 将用户输入到某一个 `<textarea>` 的值作为参数传给后台 API 接口,由其写入数据库。 function appendData(alarm_id, alarm_pic, date, event, time, remark){ var text = '<tr> <td>'+date+'</td> <td>'+time+'</td> <td>'+event+'</td>'+ '<td> <img alt="Detailed explanation of the steps to implement paging technology using ajax (with code)" >'+ '</td> <td> <textarea>'+remark+'</textarea>'+'<img alt="Detailed explanation of the steps to implement paging technology using ajax (with code)" > </td> </tr>';; $("#table table").append(text); }</textarea></textarea>
//该函数定义了如何通过 ajax 将用户输入到某一个 `<textarea>` 的值作为参数传给后台 API 接口,并写入数据库 function addEvent(alarm_id){ $("#"+alarm_id).click(function(){ var remark = $("."+alarm_id).val(); if(remark != ""){ $.ajax({ url:"/history_alarm", type:"POST", data:JSON.stringify({alarm_id:alarm_id, note:remark}), success:function(result){ var results = JSON.parse(result); if(results.status == "ok"){ console.log('ok'); } } }) } }) }</textarea>
function displayFooter(totalCount, pages, pageNo){ var newText = '共' + totalCount + '条,' + '第' + pageNo + '页,' + '共' + pages + '页'; $("#summary").text(newText); }
The function to obtain the data has been written. Next, click on the paging "Home Page, Previous Page, next page, last page, jump" events corresponding to the time. The idea is this: for each item in the paging that the user clicks on, the pageNo must be re-judged, and then the pageNo is used as a parameter to call the API interface for obtaining data again:
$("input[name='page_num']").keydown(function(e){ if(e.keyCode == 13){ $("input[name='go_btn']").click(); } }); $("input[name='go_btn']").click(function(){ var goPage = $("input[name='page_num']").val(); if(goPage >= 1 && goPage <p> I believe you have mastered the method after reading the case in this article. , for more exciting content, please pay attention to other related articles on the php Chinese website! </p><p> Recommended reading: </p><p><a href="http://www.php.cn/js-tutorial-391265.html" target="_blank">Ajax+mysql to create a message board function</a><br></p><p><a href="http://www.php.cn/js-tutorial-391262.html" target="_blank">The most basic way for ajax to realize three-level linkage concept</a><br></p>
The above is the detailed content of Detailed explanation of the steps to implement paging technology using ajax (with code). For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


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

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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