Let me explain my end goal and then maybe that will paint a picture of what I'm trying to do. Here is what my application needs to do:
- End user goes to http://www.example.com/ms_bulletins and they see a drop down menu with selectable dates.
- Once they select a date, the date is sent to my flask backend and the date is used to query the database for bulletins from that date.
- The bulletins should then return to http://www.example.com/ms_bulletins and the table should populate.
I actually have this working almost completely, except for the page does not load to show me the data. Here is some snippets of code:
JavaScript
function dateClick(date){
var dropdown = document.getElementById("date");
var date = dropdown.options[dropdown.selectedIndex].value;
console.log( "Date: " + date );
$.getJSON($SCRIPT_ROOT + '/ms_bulletins', {
date: date,
});
}
Flask
@application.route("/ms_bulletins")
def ms_bulletins():
date = request.args.get('date', None, type=str)
session = Session()
data = session.query(MsBulletins).filter(MsBulletins.date==date)
bulletins = data.all()
return render_template("ms_bulletins.html", bulletins=bulletins)
HTML
<script>
$(document).ready( function () {
$('#bulletin_table').DataTable();
} );
</script>
<div id="select_bulletin_date" onchange="dateClick(this)">
<form>
<fieldset>
<legend class="header">MS Bulletin Summary:</legend>
<select id="date">
<option name="date" value="11/8/2016">November 2016</option>
<option name="date" value="10/11/2016">October 2016</option>
</select>
</fieldset>
</form>
</div>
<hr>
<div id="ms_bulletins">
<table id="bulletin_table" class="display">
<thead>
<tr>
<th>Bulletin ID</th>
<th>Bulletin KB</th>
<th>Bulletin Name</th>
<th>Bulletin Date</th>
</tr>
</thead>
<tbody>
{% for bulletin in bulletins %}
<tr>
<td><a href="https://technet.microsoft.com/en-us/library/security/{{ bulletin.bulletin_id }}" target="_blank">{{ bulletin.bulletin_id }}</a></td>
<td><a href="https://support.microsoft.com/en-us/kb/{{ bulletin.kb }}" target="_blank">{{ bulletin.kb }}</a></td>
<td>{{ bulletin.title }}</td>
<td>{{ bulletin.date }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
Currently when the user goes to http://www.example.com/ms_bulletins, the table is blank, then the user selects a date, I can see the date being passed in the console, and then nothing happens.
If I view the source after the "render template" should have taken place, I can see in the source code that it actually worked:
Source Code
<table id="bulletin_table" class="display">
<thead>
<tr>
<th>Bulletin ID</th>
<th>Bulletin KB</th>
<th>Bulletin Name</th>
<th>Bulletin Date</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://technet.microsoft.com/en-us/library/security/MS16-142" target="_blank">MS16-142</a></td>
<td><a href="https://support.microsoft.com/en-us/kb/3198467" target="_blank">3198467</a></td>
<td>Cumulative Security Update for Internet Explorer</td>
<td>11/8/2016</td>
</tr>
<tr>
<td><a href="https://technet.microsoft.com/en-us/library/security/MS16-141" target="_blank">MS16-141</a></td>
<td><a href="https://support.microsoft.com/en-us/kb/3202790" target="_blank">3202790</a></td>
<td>Security Update for Adobe Flash Player</td>
<td>11/8/2016</td>
</tr>
</tbody>
</table>
However, the page itself never loads this data in.
Is what I'm even doing possible? And if so, what is the step I'm missing here?