的Index.html
这些按钮重定向我到包含div的,auctionBay.html auctionBay.html
我需要什么,是当我从上面按一个按钮,去auctionBay.html并据此按下了哪个,从相应的表格打印数据(category1-3 )从我的数据库到'结果'div(重要的是在div中)。 我现在有一个servlet可以使用Ajax调用
var j = jQuery.noConflict();
function myFunction() {
j.ajax({
type : 'GET',
url : '../auctionsDisplay',
success : function(data) {
j("#result").html(data);
}
});
}
auction.html负载时静态地做到这一点,但如果我手动指定类别只适用。(古董=例如类别1)
AuctionDisplay。 java的
public class AuctionsDisplay extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(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 category = "antiques";
String query = "select id, name, price from " + category;
PreparedStatement ps = con.prepareStatement(query);
ResultSet rs = ps.executeQuery();
int i;
result = "";
boolean flag = rs.next();
while (flag) {
result += "
Antiques
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");
result += "
result += "
" + rs.getString("name")
+ "
+ "
+ "data-target='#MoreInfo'style='width:90%;'>"
+ "
+ "
Highest Bid: " + price + "\u20ac
" + "Ends at: "
+ rs2.getString("ends") + "
flag = rs.next();
i++;
}
result += "
}
} catch (Exception e) {
e.printStackTrace();
}
out.println(result);
}
我明白了jQuery,AJAX,得到-post请求,JavaScript的(没有PHP请),所以我如何能实现我想要什么?这是相当简单,但它让我感到困惑
2016-09-30
Stathis
+0
使用URL查询参数,就像任何其他GET –