Skip to content

Instantly share code, notes, and snippets.

@madewulf
Created February 11, 2011 18:23
Show Gist options
  • Save madewulf/822785 to your computer and use it in GitHub Desktop.
Save madewulf/822785 to your computer and use it in GitHub Desktop.
Simplest way to do Ajax in Django?
from django.utils import simplejson
....
def problems_of_delivery(request, delivery_id):
delivery = get_object_or_404(Delivery, pk=int(delivery_id))
problem_list =[]
for problem in delivery.problem_set.all():
problem_list.append([problem.type.id , problem.comment ])
res_dict = {"date":datetime.now().strftime("%H:%M")}
res_dict["problems"]=problem_list
return HttpResponse(simplejson.dumps(res_dict), mimetype='application/javascript')
-------------------------------------
+ jquery getjson :
-------------------------------------
$.getJSON("/problems_of_delivery/"+deliveryId+"/",
function(data){
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment