ajax 페이지 작은 기능 (table) 이 아직 완벽하지 않습니다. 업데이트하고 있습니다.

2418 단어
프런트엔드 js 코드:
        autoinit(0,4)
        function refresh(pageindex){
            var parent = document.getElementById("contentlist");
            while(parent.childNodes.length > 2){
                parent.removeChild(parent.lastChild);
            }
            autoinit(pageindex,4)
        }
        
        function autoinit(pageindex,pagesize){
            $.ajax({
                type:"post",
                url:"<%=request.getContextPath()%>/servletpage",
                data:{"pageindex":pageindex,"pagesize":pagesize},
                success:function(returndata){
                    var returndata = eval(returndata);
                    for(var i = 0 ; i < pagesize ; i++){
                        newtr = document.createElement("tr");
                         newtdtitle = document.createElement("td");
                        newtdtitle.innerHTML = returndata[i].title;
                        newtdtime = document.createElement("td");
                        newtdtime.innerHTML = " ";
                        newtduser = document.createElement("td");
                        newtduser.innerHTML = returndata[i].user;
                        newtr.appendChild(newtdtitle);
                        newtr.appendChild(newtdtime);
                        newtr.appendChild(newtduser);
                        document.getElementById("contentlist").appendChild(newtr)
                    }
                }
            });

백그라운드 처리:
        int pageindex = Integer.parseInt(request.getParameter("pageindex"));
        int pagesize = Integer.parseInt(request.getParameter("pagesize"));
        try {
            List<Info> infos = new InfoDao().getInfos(pageindex,pagesize);
            JSONArray ja = new JSONArray();
            for(int i = 0 ; i < infos.size(); i++){
                JSONObject jo = new JSONObject();
                jo.put("title", infos.get(i).getTitle());
                jo.put("user", infos.get(i).getPubuser());
                ja.add(jo);
            }
            PrintWriter out = response.getWriter();
            out.print(ja);
        } catch (ClassNotFoundException | SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

좋은 웹페이지 즐겨찾기