I am new in javascript, I have created a flask site and I would like to follow ansible tower job.
I have create a specific route :
@app.route("/tower/<int:id>", methods=['POST','GET'])
def status(id):
launch = True
job_info = {}
status = refreshstatus(id)
return render_template(
'tower.html',
job_info = job_info,
status = status,
launch = launch,
id = id)
@app.route("/tower", methods=['POST','GET'])
def tower():
launch = False
if request.method == 'POST':
keyword = request.form['launchjob']
logger.info("Test | Keyword var => " + keyword)
template_id = request.form['template_id']
job_info = launch_job(template_id, keyword)
launch = True
return render_template('tower.html', job_info = job_info, launch = launch)
else:
return render_template('tower.html')
my js script:
function refresh() {
$.ajax({
url: '/tower/' + id,
dataType: 'json',
id: { id : job_info.job_id },
success: function(data) {
$('#statustable').html(data);
}
});
setTimeout(refresh, 10000);
console.log('refresh')
};
$(function(){
refresh();
});
and my html file
<th scope="row"></th>
<td> {{ job_info.job_id }}</td>
<td><p class="text-warning" id="statustable">{{ job_info.job_status }}</p></td>
<td><a href="{{ job_info.url }}" target="_blank">Lien vers le stdout</a></td>
When I refresh manually it works the job status changes, but no auto refresh.
Could you help ?
Thanks
David