On Jun 11, 2012, at 11:51 AM, cocoza4 wrote: > i tried to retrieve data from django to jquery by using get > > this is my $get in jquery > > $.get("/video/", > { > video_page: page_number > }, > function(data){ > for (var i = 0; i < data.length; i++){ > alert(data[i]['name']); > } > }); > > this code calls to view "video" of django > > def video(request): > > page = int(request.GET['video_page']) > print page > obj = Video.objects.all().order_by('date_time') > > return HttpResponse(obj) > > why i use alert(data[i]['name']); but it prompts undefined? > > thanks >
there may be other ways to do this, but I return json from my views. You can then use .getJSON (to be explicit about what's being expected). Then I run something like this: mydict = model_to_dict(obj) then you need to respond like this: return HttpResponse(json.dumps(mydict), mimetype="application/json") -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.