ajax+spring mvc を使用してコントローラから jsp を返すときに問題が発生しました。ページ全体の一部を更新したい。実際、これは表示タグテーブルです。コントローラーからこのページが送信されますが、コントローラーから返されるデータはjstlタグであり、htmlページではありません。したがって、ブラウザは確かにそのページを表示しません。
$(document).ready(function() {
alert("asdfads");
//$('#content').load('<c:url value="/pages/new.jsp"/>');
$.ajax({
url : '/shop/getCartProducts/ajax/',
type : 'GET',
async: false,
data : {},
success : function(data) {
$('#content').html(data);
alert(data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR + " : " + textStatus + " : " + errorThrown);
}
});
});
私Controller
のルックスはこんな感じ
@RequestMapping(value = "/getCartProducts/ajax/", method = RequestMethod.GET)
String ajaxGetProdCart(HttpServletRequest request, Model model) {
LOG.error("We are in the controller");
PaginatedListImpl<Product> paginatedList = new PaginatedListImpl<Product>(request);
productService.getProductsFromCart(paginatedList, null, 100);
model.addAttribute("paginatedList", paginatedList);
return "cartProduct";
}
カート製品.jsp
<display:table class="table" id="product" name="paginatedList" defaultsort="1" requestURI="/shop/cart/" excludedParams="*" export="false">
<display:column>
<a href='<c:url value="/cart/remove/"/>'> <img
src='<c:url value = "/resources/images/forbidden.png"/>'>
</a>
</display:column>
<display:column sortable="false" sortProperty="name" title="Product"
maxLength="55">
<c:url var="prodUrl" value="/product/${product.product_id}/" />
<a href='<c:out value="${prodUrl}"/>'> <c:out
value="${product.name}" />
</a>
</display:column>
<display:column property="price" paramId="price" sortable="false"
title="Price" href="#" />
<display:column property="descr" sortable="true" paramName="descr"
title="Description" maxLength="250" sortName="descr" /></display:table>
アラートでこのコードが表示されますが、html は表示されません。