0
AJAX如何將Java的Ajax應答轉移到我的foreach循環
<script>
$(document).ready(function() {
$('#selSclCatg').change(function() {
var catId = $('#selSclCatg').val();
$.ajax({
type: 'post',
url: 'CreateProCatFiltServlet',
data: {datastr: catId},
success: function (pRotyp)
{
successmessage = 'Data was succesfully captured';
$("#successmessage").text(successmessage);
},
error: function (e) {
alert('Error: ' + e.message);
}
});
});
});
</script>
如何傳輸function (pRotyp)
到foreach
循環
<p>
<label for="SelSclName">Select Scale:</label>
<select name="SelSclName" id="SelSclName">
<option>Select Scale </option>
<c:forEach items="${pRotyp}" var="at">
<option value="${at.protypid}">${at.protypnam}</option>
</c:forEach>
</select>
</p>
你在這裏嘗試的是在'jstl'中獲得'javascript'變量(pRotyp)。這是不可能的,因爲jstl和java是服務器端技術,'javascript是客戶端技術。你可以迭代javascript函數中的javascript元素。 – pikrut
protected void doPost(HttpServletRequest請求,HttpServletResponse響應) throws ServletException,IOException {response.setContentType(「text/html; charset = UTF-8」); RequestDispatcher rd = null; try(PrintWriter out = response.getWriter()){ pntcatId = Integer.parseInt(request.getParameter(「datastr」)); List pmoeList =(List )new ProductMasteroutput()。getProData(pntcatId); request.setAttribute(「pRotyp」,pmoeList); 響應); } catch(Exception e){ } } –
我同意pikrut的回答,如果你想解決這個問題,你可以使用jquery來重新渲染SelSclName節點。 – JonahCui