I've been learning Django + jQuery and so far have been able to AJAX-ify a New Post functionality. My question now is how do I display the new Post nicely and easily in the Post List AJAX-ly?
views.py:
def add_post(request):
error_msg = u"No POST data sent."
post = Post()
if request.method == "POST":
#do stuff
return HttpResponse("success")
So far I am able to return "success" and save the new Post just fine.
jQuery:
$("form#add_post").submit(function() {
//do stuff
var args = {type:"POST", url:"add_post/", data:data, complete:function(res, status) {
if (status == "success") {
alert("success");
} else {
}
}};
$.ajax(args);
return false;
})
Just alerting "success" here, and that works fine. I can see the new Post in the Post List if I refresh the page. Now how do I load the new Post AJAX-ly? Do I have to grab Post's attributes and prepend them to my DIV manually? Is there an easy way to just reload my Post List?
Thank you!