我有一個html頁面(results.html),它顯示了使用ajax調用時使用servlet檢索的表的所有內容。我需要將結果分頁。使用jquery(不使用php或jsp)從servlet結果分頁
servlet的結果打印在下面的div中。我想這使用jquery進行分頁,我不想刷新整個頁面
results.html
<div id="result2" class="container" style="margin: auto;"></div>
fetch.js
function GetCategory(category) {
\t j.ajax({
\t \t type : 'POST',
\t \t url : '../auctionsDisplay',
\t \t data : {
\t \t \t "type" : "1",
\t \t \t "category" : category
\t \t },
\t \t success : function(data) {
\t \t \t j("#result2").html(data);
\t \t }
\t });
}
這是我的doPost在se rvlet fetchServ.java
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String result = "";
try {
Connection con = DBConnection.getCon();
String type=request.getParameter("type");
String category = request.getParameter("category");
ResultSet rs=null;
PreparedStatement ps;
String query;
query = "select id, name, price from " + category;
ps = con.prepareStatement(query);
rs = ps.executeQuery();
int i;
result = "";
boolean flag = rs.next();
result += "<div class='container'><div class='row'><h1>"+category+"</h1></div>";
while (flag) {
result+="<div class='row'>";
i = 0;
while (i < 4 && flag) {
ps = con.prepareStatement("select highestBidder, ends from auctions where itemId=?");
ps.setString(1, rs.getString("id"));
ResultSet rs2 = ps.executeQuery();
rs2.next();
String price = rs.getString("price");
if (rs2.getString("highestBidder") != null)
price = rs2.getString("highestBidder");
String id=rs.getString("id");
result += "<div class='col-md-3' portfolio-item>";
result += "<div class='w3-container w3-hover-shadow w3-center'>" + "<h2 style='height:60px'>" + rs.getString("name")
+ "</h2><div class='w3-card-20' style='width:100%'>"
+ "<input id="+id+" type='image' src='../img/portfolio/w3.jpg' data-toggle='modal' "
+ "data-target='#MoreInfo'style='width:90%;'>"
+ "<div class='w3-container w3-center responsive'>"
+ "<p style='padding:5px;'>Highest Bid: " + price + "\u20ac <br> " + "Ends at: "
+ rs2.getString("ends") + "<p></div></div></div></div>";
flag = rs.next();
i++;
}
result += "</div>";
}
result+="</div>";
} catch (Exception e) {
e.printStackTrace();
}
out.println(result);
}
我已經嘗試了很多東西,但他們並沒有按照我的代碼 工作,我將不勝感激關於如何實現一些代碼(工作如果可能的話代碼)或準確的說明通過jquery分頁。 (是的,我可以更改我的代碼,並將項目放在表中)