python - display new Django object with jQuery -
i've been learning django + jquery , far have been able ajax-ify new post functionality. question how display new post nicely , in 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 able return "success" , save new post 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, , works fine. can see new post in post list if refresh page. how load new post ajax-ly? have grab post's attributes , prepend them div manually? there easy way reload post list?
thank you!
why don't return html post in success return, , use jquery append should go in page. that's in code, it's quick , easy. more complex solutions you'd want return list of json objects perhaps , use javascript framework backbone.js
Comments
Post a Comment