[Answered ]-Asynchronously update page with data that are stored by middleware

2👍

It depends on how much time you want to spend on the project. As Lorenzo stated, it might make sense to create an API and have javascript-frameworks (e.g. emberjs or angularjs) handle the asynchronity. I dont think you can handle this with pure django…
If you don’t have time and are in for some ‘hack’ you could just replace the content of your page by polling the url and replacing the whole document with the response:

 $.ajax({
        type: "GET",
        url: "<url_to_your_requests_view>",
        success: function(response){
            $('body').html(response);
        }
    });

This is NOT clean, but should work as a quick an dirty trick…

EDIT: If you only want to exchange certain parts of your site, you can break it down to just add elements to the page:

 $.ajax({
        type: "GET",
        url: "<url_to_your_requests_view>",
        success: function(response){
            var newlyAddedRows = // find your newly added rows through some jquery
            newlyAddedRows.forEach(function(row){
                $('#request-holder').append(row);
            });

        }
    });

OR WITH JSON

 $.ajax({
        type: "GET",
        url: "<url_to_your_requests_api_endpoint>",
        success: function(response){
            var requestRows = response.requestItems
            var $requestsHolder = $('#request-holder');
            $requestHolder.empty();
            requestRows.forEach(function(row){
                requestsHolder.append('<div class="request-row">' + <visualize your data somehow> + '</div>'); //e.g. row.timestamp if you have that in your json
            });

        }
    });

Leave a comment