I have a simple code in my template.html:
<div>
<input type="button" id="buttonId" value="Show Data">
</div>
<script>
$('#buttonId').click(function() {
$.ajax({
method: 'POST',
data: {
csrfmiddlewaretoken: csrf_token,
click: true
},
success: function(response){
console.log(response) // it is a HTML, not my data
}
});
});
</script>
{{results}}
And in my views.py:
if request.POST.get('click', False):
... #here I get finalresults
return render(request, 'template.html', context={
'results': finalresults
})
When I push the Button, the script runs. So I know that after pushing the button, finalresults has content, but this content does not arrive to the HTML template.
What am I doing wrong?