Zartch
Zartch

Reputation: 1025

Django template, reload after javasctipt post

I have a javascript function called by an input, an the input calls a Django 1.8 view, adding a post parameter.

<script type="text/javascript">
            function modpost(action, pkpost){
               var retVal = prompt("Raò rebutj : ", "");
               $.post('/cela/acceptarRebutjarPost/'+pkpost+"/"+action, {'text': retVal});
               //$.get('{% url 'missatge_cela' %}')
               //location.reload();
            }
</script>

<input type="button" value="NO" onClick="modpost('cancel', {{ post.pk }});" />

The post reach the view ok, but the render of a view do not refresh the page

def acceptarRebutjarPost(request,pkpost, action):
    *****//Some code heare//*****         
    return render(request, "moderacio/mode_post.html", {'posts':posts} )

With location.reload(); the post don't reach the view (don't stop in debug mode and don't do the action) If i set a timeout, the refresh doesn't happens. And with the $.get nothing happens. I can see the get request in inspector, but nothing happens.

How i can reload the page from the javascript? What I'm missing?

Upvotes: 0

Views: 314

Answers (1)

davko
davko

Reputation: 459

You need to call location.reload inside the post call:

$.post(
    '/cela/acceptarRebutjarPost/'+pkpost+"/"+action,
    {'text': retVal},
    function(response){ location.reload(); }
);

Upvotes: 1

Related Questions