Answer the question
In order to leave comments, you need to log in
How to update a block without reloading the page?
Good afternoon!
Tell me how to update (without reloading the page) only the table, and not the entire page.
HTML Template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="test">
{% for table in tables %}
{{ table|safe }}
{% endfor %}
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
function mode() {
$.ajax({
url: "/hello",
type: "get",
success: function(response) {
$("#test").html(response);
},
error: function(xhr) {
//Do Something to handle error
}
});
};
setInterval(mode, 2000);
</script>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
You display tables on the whole page in a block<div id="test">
<div id="test">
{% for table in tables %}
{{ table|safe }}
{% endfor %}
</div>
<div id="test">
replace all the content with what's in the response .
try$("#test").html(response);
$("#test").append(response)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question