I am new to Web2Py, Python stack. I have a simple requirement to implement. I need to pass some data from a UI form to a Controller action for processing. After processing the data that action returns a response back to the view which I need to render as an HTML table on the same view. I am using AJAX for this purpose.
I am able to get the response back to the view but don't know how to iterate over the elements of that response to render as an HTML table. When I run the below code all it does is replace the entire target DIV with the response content.
I know it's pretty straightforward to this in Java, Grails, PHP, etc. But, I am struggling to find a way to that in Web2Py.
I have the following snippets in my code: index.html:
<script>
jQuery('#input_form').submit(function() {
ajax('{{=URL('process_form')}}',
['input_var1','input_var2','input_var3','input_var4'], 'results_div');
return false;
});
<div id="results_div">
<form>
<div class="table-responsive">
<table id="records_table" class="table table-bordered">
<tr>
<th>Col Head 1</th>
<th>Col Head 2</th>
<th>Col Head 3</th>
<th>Col Head 4</th>
</tr>
<tr>
<td>Col Content 11</td>
<td>Col Content 12</td>
<td>Col Content 13</td>
<td>Col Content 14</td>
</tr>
<tr>
<td>Col Content 21</td>
<td>Col Content 22</td>
<td>Col Content 23</td>
<td>Col Content 24</td>
</tr>
</table>
</div>
</form>
</div>
default.py
def process_form():
results = request.vars
return DIV(results)
Any help in this regard would be greatly appreciated.