How to transfer java Ajax Answer to my foreach loop <p><strong>AJAX</strong></p> <pre><code> &lt;script&gt; $(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); } }); }); }); &lt;/script&gt; </code></pre> <p>How to transfer <code>function (pRotyp)</code> to <code>foreach</code> loop</p> <pre><code> &lt;p&gt; &lt;label for="SelSclName"&gt;Select Scale:&lt;/label&gt; &lt;select name="SelSclName" id="SelSclName"&gt; &lt;option&gt;Select Scale &lt;/option&gt; &lt;c:forEach items="${pRotyp}" var="at"&gt; &lt;option value="${at.protypid}"&gt;${at.protypnam}&lt;/option&gt; &lt;/c:forEach&gt; &lt;/select&gt; &lt;/p&gt; </code></pre>