[英]How to get list from Servlet to JSP through Ajax
I have a piece of code in a servlet我在 servlet 中有一段代码
response.setContentType("application/json");
new Gson().toJson(list, response.getWriter());
I have a code in ajax我在 ajax 中有一个代码
$.ajax({
url: '${pageContext.request.contextPath}/Sort',
type: 'POST',
dataType: "json",
data: {
value : value,
name : name,
lowestPrice : lowestPrice,
highPrice: highPrice
},
success: function (response) {
},
error: function () {
}
});
I have a code in jsp我在 jsp 中有一个代码
<c:forEach var="x" items="${allProduct}">
<div class="hover-all-product">
<a class="all-product-item" href="${pageContext.request.contextPath}/Product?id=${x.maLapTop}">
<div class="status-sale">-11%</div>
<div class="img-all-product-item"
style="background-image: url('${root}${x.linkHinh1}')">
</div>
<div class="status">HẾT HÀNG</div>
<div class="infor-all-product-item">
${x.tenLaptop}
</div>
<div class="price-all-product-item">
${x.giaBan}
</div>
<div class="sale-all-product-item">
<span class="origin-price">33.999.000đ</span> <span>11%</span>
</div>
</a>
</div>
</c:forEach>
How can I assign the value of list in servlet to allProduct in jsp through ajax如何将servlet中列表的值分配给jsp到ajax中的allProduct
Think of when which piece of code will run.想想哪段代码何时运行。
So have a closer look at your JavaScript code to tackle the problem.因此,请仔细查看您的 JavaScript 代码以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.