[Answer]-Django- update division of base template after post without reload

1๐Ÿ‘

โœ…

I think you shouldnโ€™t mix in the same time the post form, template tags and Ajax excepted if your notifications are coming from the two ways (template-views and Ajax). If i was you I would do everything with Ajax+javascript only.

Replace your form with just a button containing a function in โ€œonclickโ€ attribute which will do the Ajax call to your notification view then update you div tag with the success callback.

<script>
    function loadNotification() {
        $.get( "/url/to/notifications", function( data ) {
            $( "#notify-form" ).html( data );
        });
    }
</script>

<input id="clickMe" type="button" value="clickme" onclick="loadNotification();" />

Also, I would use GET request instead of POST.

I hope I am clear enough ๐Ÿ˜‰

๐Ÿ‘คsamidarko

0๐Ÿ‘

I urge you to look at the Django messages framework, rather than write your own notification application. It is trivial to hook it up to a $.get() when necessary.

๐Ÿ‘คken

Leave a comment