Reputation: 1325
The task: i have a Chart that feeds of some data which is continuosly updated throughout the day. Specifically, the data is extracted from the web, it's written in the database and such database is read by a django view and later visualized in the aforementioned Chart.
The problem: I want the user to see the new data without reloading the page. Looking online, using Django, i think I have to link it to a rest api, the problem is that in practice i have no cliente how to set it up.
The question: is this the best way to do it? If so, could you point me to some tutorials that make this happen?
Upvotes: 0
Views: 1812
Reputation: 3954
I'm preety sure a combination of JQuery and AJAX can do the trick. See: Update data on a page without refreshing and How to update data on field on a website from SQL database with AJAX and Django. I think the best example is in this SO question: setInterval and Ajax
Perhaps the following code snippet can be useful for you, which is supposed to be added in the html template.
<script type="text/javascript">
$(function() {
function callAjax(params, title, url){
$.ajax({
#<<<here you build the request, the html-POST>>>
}
});
};
function regularCall() {
callAjax("", "", "{% url 'the-url-that-you-expect-from-django-side' %}");
};
setInterval(regularCall, 10000); // Time in milliseconds
callAjax("", "", "{% 'the-url-that-you-expect-from-django-side' %}"); // First Call
});
</script>
Upvotes: 1