I'm developing a dice roller app; I'm using Django (2.1), Bootstrap (4), mySQL, a pinch of JavaScript, and now AJAX, which is where I am struggling. I'm passing a queryset into the template as a kwarg, and then rendering that as an "action log" (history of the dice rolls) in it's own div. I thought that I could just use AJAX to reload that div, but I seem to be missing something. I'm using, amongst other things, this stackoverflow question as a reference.
template.html
<div class="container-fluid" id="action_log" style="padding:0">
... <!--display actions-->
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function refresh_action_log(){
$.ajaxSetup ({
cache: false,
complete: function() {
setTimeout(refresh_action_log, 2000);
}
});
$('#action_log').load(document.URL + '#action_log');
})
</script>
What I think should happen is that, after 2 seconds (2000 ms), the AJAX should refresh only the named div. One thing I know I have questions about is the syntax of the last line in the function. In the comments on the page linked above, I see a couple different syntaxes, and I can't figure out which one is right.
What have I missed?
(eta: well, one thing I missed was a closing paren...)
Thanks, -Van