Search code examples
djangojqueryjquery-loadjquery-post

django jquery post then load


Trying to get a section on my site working when it basically acts in the same way as facebooks wall post

user sees a box where they input some information about how they feel, then I use a jQuery $.post method to submit the data, and then I would like to retrive the new data.

Currently this is what I have.

<script type="text/javascript">

    $("#testform").submit(function(){
        $.post("/wall/new/", $("#testform").serialize());
        $('#id_text').val('');
        $(this).ajaxComplete(function() {
            $('#news').load('/wall/');
        });
        return false;

    });
</script>

And then the HTML looks like this

<div id="news">
    <h4>{% trans "News feed" %}</h4>

    <form method="post" action="/wall/new/" id="testform">
        <textarea id="id_text" class="wall-input" style="max-height: 100px;" rows="1" name="text"></textarea>

        <input type="submit" value="{% trans 'share' %}" class="blue" id="submit-wall"/>
        <div class="clearfix"></div>
    </form>
</div>

Solution

  • $.get seemed to solve the issue instead

    $(this).ajaxComplete(function() {
        $.get('/wall/', { user:'myuser'}, function(data){
            $('#news').html(data);
        });
    });