


AJAX + SpringMVC implements the paging query function of bootstrap modal box
This article mainly introduces AJAX SpringMVC to implement the paging query function of bootstrap modal box, as well as the modal box ajax paging example code sharing. It is very good and has reference value. Friends who need it can refer to it
1. Rendering
##2. JS
function getManagerList(dealerId,page2){ macAddress = document.getElementById("activeXDemo").getMac(); $.get("${ctxPath}/common/dealer/manager?"+Math.random(), { page2: page2, pageSize2: 9, dealerId: dealerId, macAddress:macAddress }, function(data){ if(data){ var managerList=data.managerList; var uploadDir=data.uploadDir; var rs = ""; for (var i=0;i<managerList.length;i++) { var name=managerList[i].personName; var picPath=managerList[i].picPath; if(picPath==null){ var path="${ctxPath}/resources/assets/imgs/no_pic.png"; }else{ var path="${ctxPath}"+uploadDir+picPath; } rs+="<p class='col-xs-4 demo1_box'>"; rs+="<img src="/static/imghwm/default1.png" data-src="https://img.php.cn/upload/article/000/118/027/88a626d2dd26ee551c5171aacf0ce8b8-1.png?x-oss-process=image/resize,p_40" class="lazy" style="max-width:90%"; rs+=path; rs+="'>"; rs=rs+"<p>"+name+"</p></p> "; } $('#managerList').empty(); $('#managerList').append(rs); var page2=data.page2; var stor_no2=data.stor_no2; var pageCount2=data.pageCount2; var pagination = ""; pagination+="<ul class='pagination pager_cus'>"; pagination=pagination+"<li><a>第 "+(page2 + 1); pagination=pagination+" 页/共 "+pageCount2+" 页</a></li>"; pagination += "<li><a href='javascript:getManagerList(\""; pagination += dealerId; pagination += "\","; pagination += 0 + ");'>« 首页</a></li>"; if(page2>0){ pagination += "<li><a href='javascript:getManagerList(\""; pagination += dealerId; pagination += "\","; pagination += (page2 - 1) + ");'>« 上一页</a></li>"; } var start=page2-3; var end=page2+3; if(start<0){ end=end-start; } if(end >(pageCount2-1)){ end = pageCount2-1; start=end -7; } for(var j=start;j<=end;j++){ if(j>-1 && j<pageCount2){ if(page2==j){ pagination += "<li class='active'><a href='javascript:getManagerList(\""; pagination += dealerId; pagination += "\","; pagination += j + ");'>"+(j+1)+"</a></li>"; }else{ pagination += "<li><a href='javascript:getManagerList(\""; pagination += dealerId; pagination += "\","; pagination += j + ");'>"+(j+1)+"</a></li>"; } } } if(page2<pageCount2-1){ pagination += "<li><a href='javascript:getManagerList(\""; pagination += dealerId; pagination += "\","; pagination += (page2 + 1) + ");'>下一页 »</a></li>"; } pagination += "<li><a href='javascript:getManagerList(\""; pagination += dealerId; pagination += "\","; pagination += (pageCount2 - 1) + ");'>« 尾页</a></li>"; $('#pagination').empty(); $('#pagination').append(pagination); $('#personAddModel').modal('show'); } } ); } </script>
3. Modal box
<p style="display:none;" class="modal fade bs-example-modal-lg in" id="personAddModel" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false"> <p class="modal-dialog modal-lg"> <p class="modal-content" id="personAddModelContent"> <p class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> <span class="modal-header-title" id="myModalLabel">经营人员</span> </p> <p class="modal-body"> <p class="row"> <p class="col-xs-12" id="managerList"> </p> </p> </p> <p class="modal-footer" id="pagination"> </p> </p> </p>
4. controller
@RequestMapping(value = "manager", method =RequestMethod.GET) public @ResponseBody ModelAndView queryManager(Model model , @RequestParam(defaultValue = "0")int page2 , @RequestParam(defaultValue = "9")int pageSize2 , @RequestParam(required = false, defaultValue = "")String dealerId , String macAddress){ FastJsonJsonView view = new FastJsonJsonView(); if(macAddService.checkMacAddress(macAddress, "E")==true){ String uploadDir = this.localUploadTools.getPreviewDir() + "/dealerUpload"; PaginationSupport<ManagePersonForTouchScreenVO> managerVOPS = dealerService.queryManager(dealerId, page2, pageSize2); view.addStaticAttribute("page2", page2); view.addStaticAttribute("uploadDir", uploadDir); view.addStaticAttribute("managerList", managerVOPS.getObject()); view.addStaticAttribute("stor_no2", managerVOPS.getTotalCount()); view.addStaticAttribute("pageCount2", managerVOPS.getPageCount()); } return new ModelAndView(view); }Okay,
The following introduces you to the bootstrap modal box ajax paging example code. First, I will show you the rendering:
The rendering:
/** * ajax分页 */ $(function(){ $(".modal-body").find(".pagination").on("click","li",function(){ var totalPage=$(".modal-body").find(".pagination").find(".lilength").length; var pageNo=$(this).find("a").text(); var beforePage=""; //获取之前选中的值 $(".modal-body").find(".pagination").find("li").each(function(){ if($(this).hasClass("active")){ beforePage=$(this).find("a").text(); } }); //alert(beforePage); if($(this).find("a").text()=="首页"){ removeClass(); $(".modal-body").find(".pagination").find("li").each(function(){ if($(this).find("a").text()=="1"){ $(this).addClass("active"); } getPlanFy("1"); }); }else if($(this).find("a").text()=="上页"){ if(beforePage==1){ showMessage("已经是第一页了!") }else{ var dqy=parseInt(beforePage)-1; $(".modal-body").find(".pagination").find("li").each(function(){ if($(this).find("a").text()==dqy.toString()){ $(this).addClass("active"); }else{ $(this).removeClass("active"); } }); getPlanFy(dqy); } }else if($(this).find("a").text()=="下页"){ if(beforePage==totalPage){ showMessage("已经是最后一页了!") }else{ var dqy=parseInt(beforePage)+1; $(".modal-body").find(".pagination").find("li").each(function(){ if($(this).find("a").text()==dqy.toString()){ $(this).addClass("active"); }else{ $(this).removeClass("active"); } }); getPlanFy(dqy); } }else if($(this).find("a").text()=="末页"){ removeClass(); $(".modal-body").find(".pagination").find("li").each(function(){ if($(this).find("a").text()==totalPage){ $(this).addClass("active"); } }); getPlanFy(totalPage); }else{ removeClass(); $(this).addClass("active"); getPlanFy(pageNo); } }); // $(".table").find("tbody").on("click",".showMsgDetail",function(){ // var msg=$(this).find("a").attr("name"); // showMagDetail(msg); // }); $(".addbutton").click(function(){ $("#savePlanmodal").removeAttr("name"); $("#planIdsUpdate").val(""); }); }); /** * 弹窗 */ function showMessage(content){ $.alert({ title: '提示', content: content,//支持html icon: 'fa fa-rocket', animation: 'zoom', closeAnimation: 'zoom', buttons: { okay: { text: '确定', btnClass: 'btn-primary' } } }); } /** * 移除css */ function removeClass(){ $(".modal-body").find(".pagination").find("li").each(function(){ $(this).removeClass("active"); }); } function getPlanFy(pageNo){ var pageSize=10; $.post(""+otherPath+"/fault-studio/getInpectPlanList.action", {"pageNo":pageNo,"pageSize":pageSize},function(data){ $("#inspectionPlan").find(".modal-body").find("table").find("tbody").html(""); $("#inspectionPlan").find(".modal-body").find(".pagination").html(""); var appendHtml=""; if(data.items!=null && data.items.length>0){ $.each(data.items,function(i,item){ var number=parseInt(i)+1; appendHtml+="<tr>" + "<td align='center'>"+number+"</td>" + "<td><a>"+item[1]+"</a></td>" + "<td>"+item[2]+"</td>"+ "<td>"+item[3]+"</td>"+ "<td><a name='"+item[0]+"' onclick='updatePlan(this)'>修改</a> <a lang='"+item[0]+"' onclick='delPlan(this)'>删除</a></td>" "</tr>" }); $("#inspectionPlan").find(".modal-body").find("table").find("tbody").append(appendHtml); var paginHtml=""; if(isNotTirmpagin(data.totalPage) && data.totalPage>0){ paginHtml+="<li><a>首页</a></li>" + "<li><a>上页</a></li>"; for(var j=0;j<data.totalPage;j++){ var page=parseInt(j)+1; if(page==pageNo){ paginHtml+="<li class='lilength active'><a>"+page+"</a></li>"; }else{ paginHtml+="<li class='lilength'><a>"+page+"</a></li>"; } } paginHtml+="<li><a>下页</a></li>" + "<li><a>末页</a></li>"; $("#inspectionPlan").find(".modal-body").find(".pagination").append(paginHtml); } } }); } function updatePlan(obj){ var planId=obj.name; $.post(""+otherPath+"/fault-studio/getPlanById.action",{"id":planId},function(data){ if(data.result=="success"){ $(".addbutton").click(); var item=data.items; $("#planName").val(item.name); $("#planTitle").val(item.inspectTitle); $("#showTime").val(item.inspectTime); var module_name=item.module_name; var nameArray=module_name.split("&"); var moudleIdArray=item.inspectContent.split("&"); var nameHtml=""; if(nameArray!=null && nameArray.length>0){ for(var i=0;i<nameArray.length;i++){ if(isNotTirmpagin(nameArray[i])){ nameHtml+="<li id='"+moudleIdArray[i]+"'>"+nameArray[i]+"</li>"; } } } $(".inspectContent").append(nameHtml); var inspectTimeArray=item.inspectTime.split("&"); var timeHtml=""; if(inspectTimeArray!=null && inspectTimeArray.length>0){ for(var j=0;j<inspectTimeArray.length;j++){ if(isNotTirmpagin(inspectTimeArray[j])){ timeHtml+="<li>"+inspectTimeArray[j]+"</li>"; } } } $(".inspectionChooseTime").append(timeHtml); $("#savePlanmodal").attr("name","update"); $("#planIdsUpdate").val(planId); } }); } function delPlan(obj){ var planId=obj.lang; sureConfirm("提示","确定删除吗?",planId); } function showMagDetail(msg){ $.alert({ title: '提示', content: msg,//支持html icon: 'fa fa-rocket', animation: 'zoom', closeAnimation: 'zoom', buttons: { okay: { text: '确定', btnClass: 'btn-primary' } } }); } function sureConfirm(tip,msg,planId){ $.confirm({ title: tip, content: msg, icon: 'fa fa-rocket', animation: 'zoom', closeAnimation: 'zoom', buttons: { confirm: { text: '确定', btnClass: 'btn-primary', action:function(){ $.post(""+otherPath+"/fault-studio/delInspectPlan.action",{"id":planId},function(data){ if(data.items=="success"){ showMagDetail("删除成功"); getPlanFy("1"); }else{ showMagDetail(data.msg); } }); } }, cancle: { text: '取消', action:function(){ return false; } } }, }); } function isNotTirmpagin(obj){ if(obj!=null && obj!='' && obj!=undefined){ return true; }else{ return false; } }The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. Related articles:
How to implement Ajax dynamically adding data to the drop-down list
Set Access-Control-Allow- Origin implements cross-domain access
Ajax implements the function of registering and selecting an avatar and uploading it
The above is the detailed content of AJAX + SpringMVC implements the paging query function of bootstrap modal box. 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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools