I am doing a POST request from ajax to python flask like below.
function humval(val1,val2){
var dict = {"url":$('#url'+val1).val(),"status":val2};
$.ajax({
url: '/testroutez',
contentType: 'application/json;charset=UTF-8',
data : JSON.stringify(dict),
type: 'POST',
success: function(response){
alert('success');
console.log(response);
},
error: function(error){
alert('error occured');
console.log(error);
}
});
}
Html code is handling jinja format
<tbody>
{% for value in myData %}
<tr>
<td class="urlTd">
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
{{ value["url"] }}
</td>
<td>{{ value["org"] }}</td>
<td>{{ value["val_date"] }}</td>
<td>
<input type="hidden" value="{{value['url']}}" id='url{{ loop.index }}'>
<input type="button" onclick="humval('{{ loop.index }}','valid')" type="button" class="far fa-check-circle hButton" id="hvalid">
<input type="button" onclick="humval('{{ loop.index }}','invalid')" type="button" class="fas fa-times-circle hButton" id="hinvalid">
</td>
</tr>
{% endfor %}
</tbody>
flask code is
@data_sources_api.route('/testroutez', methods=["POST"])
def testroutez():
if loggedin():
if request.method== 'POST':
print("request received")
data_json = request.get_json()
result_l = MlData.objects(hum_proc='null')
myData = mldatas_schema.dump(result_l)
return render_template('users/validation.html', myData = myData)
What is tried is to render the template again with new value myData. But as the request is passing from ajax, it wont work and again the whole page will get refreshed. But I want the table alone to refresh with new values. How it is possible to do like that