views:

57

answers:

2

Hey.

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>
A: 

$.get seemed to solve the issue instead

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

Unless you are wedded to handling all of the AJAX detail yourself, take a look at the jQuery taconite plugin. It makes fire-and-forget AJAX functionality trivial to implement.

Peter Rowell