Created
February 11, 2011 18:23
-
-
Save madewulf/822785 to your computer and use it in GitHub Desktop.
Simplest way to do Ajax in Django?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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