views:

23

answers:

0

Hey, i think this is simple, but I can't get it to work! :(

def ajax_filter(request):
    area_id = request.REQUEST.get('area_id')

    outlets = Outlet.objects.filter(zipcode__area=area_id)

    json_serializer = serializers.get_serializer("json")()
    data = json_serializer.serialize(list(outlets), ensure_ascii=False)

    return HttpResponse(data,  mimetype='application/json')

This works fine, I got at pretty JSON output

Javascript
$.ajax({
    type: "GET",
    data: "area_id="+area_id,
    url: '/ajax_filter/',
    dataType: "json",
    success: function(data) {
        alert(data.length)
    }
});

The data.length returns "1" - And there are 4 entries :(

alert(data[0].fields.name) gives the right name of the object.name! but data[1] gives me nothing :(

How can I loop through all the entries ??