current position:Home>Using Ajax to realize non refresh paging
Using Ajax to realize non refresh paging
2022-05-15 02:40:45【Bugxiu_ fu】
JSON: Object string ( Meet the definition rules of objects )
var obj = {"name":"value","name":"value"};
JSON Use
front end :
Original ecology js:JSON.parse(json) stringify() jQuery:parseJSON
Back end
fastJSON
object 《----》JSON character string JSON.toJSONString(obj);
JSON.parseObject(str, object .class);
jackJSON
ObjectMapper mapper = new ObjectMapper();
mapper.writeValueAsString(obj); mapper.readValue(str, object .class);
AJAX Use
let path = "${pageContext.request.servletContext.contextPath}";
No refresh page syntax rules :
$.ajax({ url:path+"/hell.do", type:"post", data:{"username":"admin","password":"123"}, datatype:"json", success:function(data){ //data Related treatment } }); $.post(path+"/hello.do",{"username":"admin","password":"123"},function(data){ });
Code display :
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> No refresh paging </title>
<!-- Import jQuery Class library -->
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
// Get project path
let path = "${pageContext.request.servletContext.contextPath}";
let pageIndex = 1;// Control the next or previous page of the front end After clicking Page number of
let pageMax = 0;// Maximum page number Expand scope
let searchName="";
$(function() {
myload();
});
function myload(searchName){
$.post(path+"/amdinGoodsList.do",{"pageIndex":pageIndex,"searchName":searchName},function(data){
//console.log(data);
//$("#content").html(data);
// First escape to array
let list = $.parseJSON(data);
// Maximum pages
pageMax = list.pageMax;
//console.log($.type(list));
// Traverse
let str = "<table border = '1' width = '100%'>";
str+="<tr>";
str+="<th> Number </th>";
str+="<th> name </th>";
str+="<th> type </th>";
str+="<th> picture </th>";
str+="<th> Price </th>";
str+="<th> stock </th>";
str+="<th> describe </th>";
str+="<th> operation </th>";
str+="</tr>";
$.each(list.adminListGoods,function(index,object){
//console.log(index,object.gname);
str+="<tr>";
str+="<td>"+object.gid+"</td>";
str+="<td>"+object.gname+"</td>";
str+="<td>"+object.gtype+"</td>";
str+="<td><img src = '"+object.gimage+"' width = '80' height = '60' /></td>";
str+="<td>"+object.gprice+"</td>";
str+="<td>"+object.gkc+"</td>";
str+="<td>"+object.ginfo+"</td>";
str+="<td><button> Delete </button><button> modify </button></td>";
str+="</tr>";
});
str+="</table>";
// United will str Append to content in
$("#content").html(str);
$("#pIndex").html(pageIndex);
$("#pMax").html(pageMax);
});
}
function nextPage(a) {
// Implement the method on the next page
if(a==2){
if(pageIndex>=pageMax){
pageIndex=pageMax;
return;
}else{
pageIndex++;
}
}
// Implement the method on the previous page
if(a==1){
if(pageIndex<1){
pageIndex--;
}else{
pageIndex=1;
}
}
// Implementation method of home page
if(a==3){
pageIndex=1;
}
// The method of realizing the last page
if(a==4){
pageIndex=pageMax;
}
// Call the refresh method again
myload();
}
</script>
</head>
<body>
<div id="content">
</div>
<div id="pageCount">
<span id="pIndex"></span>/<span id="pMax"></span>
<a href="javascript:nextPage(3);"> home page </a>
<a href="javascript:nextPage(1);"> The previous page </a>
<a href = "javascript:nextPage(2);"> The next page </a>
<a href="javascript:nextPage(4);"> Tail page </a>
</div>
</body>
</html>
The jump servlet Interface :
package com.zking.cart.ht.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zking.cart.biz.IGoodsBiz;
import com.zking.cart.biz.impl.GoodsBizImpl;
import com.zking.cart.entity.Goods;
import com.zking.cart.utils.GetUtils;
// Display data in the background servlet
@WebServlet("/amdinGoodsList.do")
public class adminGoodsListServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request,
*
* HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request,
*
* HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
// 1. Set request and response encoding
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
Integer pageIndex = 1;
Integer pageSize = 3;
// 2. Processing requests
String pIndex = request.getParameter("pageIndex");
if (null != pIndex) {
pageIndex = Integer.valueOf(pIndex);
}
Integer pageCount = new GetUtils().getTableCount("tb_goods", "gname", "");
Integer pageMax = pageCount % pageSize != 0 ?pageCount / pageSize + 1 : pageCount / pageSize;
// 3. Processing requests ( call biz Save through domain object )
IGoodsBiz biz = new GoodsBizImpl();
List<Goods> adminListGoods = biz.queryGoodsAll(pageIndex, pageSize, "");
// map Set save
Map<String, Object> maps = new HashMap<String, Object>();
maps.put("adminListGoods", adminListGoods);
maps.put("pageMax", pageMax);
ObjectMapper mapper = new ObjectMapper();
String writeValueAsString =mapper.writeValueAsString(maps);
PrintWriter out = response.getWriter();
out.write(writeValueAsString);
out.flush();
out.close();
}
}
copyright notice
author[Bugxiu_ fu],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/135/202205142119593817.html
The sidebar is recommended
- React error report record
- Analysis of react life cycle function
- react demo1 TodoList
- Summary of the differences between state and props in react
- Difference between controlled components and uncontrolled components in react
- Node. JS use get Stream download file
- How does JavaScript copy arrays instead of references
- JavaScript calculates the number of days, hours, minutes and seconds between days
- JQuery get page address parameters
- JavaScript create Download
guess what you like
node. JS traversal directory
Tips for using JavaScript string split (how to keep the delimiter)
Common CSS notes
JavaScript usage Get the address of the regular function
New generation node JS web development framework koa zero foundation entry learning notes
JavaScript notes
asp. Net core method for modifying HTML without rerun
Summary of compatibility processing of H5 + Vue cli project in Safari browser
Summary of amap scheme of Gaode map used in vue3 + TS project
Summary of filter scheme used in JS code in Vue
Random recommended
- Build an electron project based on Vue from scratch
- In Vue project, solve the problem of verification conflict when eslint and prettier are used at the same time
- Vue3 + vuecli4 solve chunk vendors JS file is too large. Scheme summary
- Scheme summary of eslint check before vue3 + vite configuration project operation and eslint check before git submission
- Fatal authentication failed for 'httpxxxx Git 'solution
- Vue's solution to the compatibility of hevc encoded video in each end browser
- Record the solution to the error in obtaining the picture in springboot in Vue
- [Vue] detailed analysis of the life cycle function of Vue components
- [Vue] deeper understanding of user-defined attribute props
- [Vue] front end error: cannot read properties of undefined (reading 'split')
- [Vue] asynchronous problem of component value transfer -- the sub component gets the data slowly
- [Vue] Vue data changes, but the page is not updated in real time
- [element UI] use of form verification -- detailed explanation
- [Vue] use of slots - Review
- The influence on the fixed positioning element of the inner layer when the outer element has a fixed height and overflows and rolls
- Precautions
- Change detection strategy of angular component
- Angular service and @ injectable
- JS, HTML and CSS are not compatible and do not use common knowledge
- Properties to be known in angular @ component
- Angular acquisition and operation DOM
- Html2canvas problem
- Use day in Vue JS (time and date processing library)
- Vue cli configuring preprocessor global variables (take less as an example)
- How to use H5 custom tags in Vue?
- Come on, vue2 customize global loading
- Come on, Vue move the end suspension ball assembly
- React routing foundation and transmission parameters
- Come on, Vue graphic verification code component
- JavaScript judges browser types and kernels at home and abroad (including 360, QQ, Sogou, etc.)
- ArcGIS JavaScript 4. Generates a rectangular buffer at the point of X
- Node under window JS installation, environment configuration, setting Taobao image
- Understanding of prototype and prototype object of JavaScript
- How to customize the startup port of react project!
- Why vue3 0 using proxy to realize data listening 2021-06-21
- Front end artifact - download, configuration and use process of Charles (vase) [Mac version]
- React next configures SVG loader and supports SVG configurability
- React native Android phone cannot be opened after installation. Flash back!
- Fetch and Axios failed to request on Android, with error messages: network request failed and network error
- How to upgrade react Babel 7.1.0