Trying to apply this ajax plugin for django https://github.com/yceruto/django-ajax I'v used ajaxPost successfully, but can't apply ajaxGet
In views.py. In python all data is printed fine.
@ajax
def notify(request):
notifications = Notification.objects.filter(whom=request.user.profile)
for acd in notifications:
print(acd)
print(acd.choice_afl)
print(acd.whom)
print(acd.who_did)
return {'notifications': notifications}
In html:
$('.notifications_button').click(function(){
ajaxGet('/notify/', function(notifications){
for(var acd in notifications){
alert(acd.choice_afl)
$('#the_very_nw').html(acd.choice_afl);
}
})
If I alert noty
I get "notifications"
, if I alert acd.choice_afl
I get undefined
(or just nothing if insert into html), despite in python I get the sting result I need . What is wrong? Doesn't python object transforms into JSON object?
EDIT: Also for safe I serialized django object into json like this. No changes
data = serializers.serialize("json",notifications)
return {'notifications': data}
EDIT2: I watched the structure of JSON
var jsonPretty = JSON.stringify(JSON.parse(data),null,2);
$('#the_very_nw').html(jsonPretty);
and it looks like this. So I missed 'fields' but it changed nothing. Still nothing is printed. And that is in case if I return HttpResponse :
[ { "fields": { "how_much_new_notifications": 0, "number_of_new_notifications": 0, "who_did": 2, "question_answered_object": null, "whom": 1, "choice_afl": "F" }, "model": "blog.notification", "pk": 1 }, { "fields": { "how_much_new_notifications": 0, "number_of_new_notifications": 0, "who_did": 2, "question_answered_object": null, "whom": 1, "choice_afl": "F" }, "model": "blog.notification", "pk": 2 }, { "fields": { "how_much_new_notifications": 0, "number_of_new_notifications": 0, "who_did": 2, "question_answered_object": null, "whom": 1, "choice_afl": "F" }, "model": "blog.notification", "pk": 3 }, { "fields": { "how_much_new_notifications": 0, "number_of_new_notifications": 0, "who_did": 2, "question_answered_object": null, "whom": 1, "choice_afl": "F" }, "model": "blog.notification", "pk": 4 }, { "fields": { "how_much_new_notifications": 0, "number_of_new_notifications": 0, "who_did": 2, "question_answered_object": null, "whom": 1, "choice_afl": "F" }, "model": "blog.notification", "pk": 5 }, { "fields": { "how_much_new_notifications": 0, "number_of_new_notifications": 0, "who_did": 2, "question_answered_object": null, "whom": 1, "choice_afl": "F" }, "model": "blog.notification", "pk": 6 } ]