I am returning a QuerySet of 1 and my JQuery looks like this
<script>
$(document).ready(function(){
$("#search_form").submit(function(event)
{
event.preventDefault();
$.ajax({
type: "POST",
url: "object/search/",
processData: false,
dataType: "json",
success: function(data){
$.each(data, function(key, value){
alert( key + ': ' + value );
});
}
});
});});
</script>
The alert will show up but all it returns 0: [object Object]. I would like to display the name property of the Object model that is being returned. Like using object.name. I am really stuck, your help in solving this problem is appreciated.
The code for my view is:
if request.is_ajax():
if request.method == 'POST':
format = 'json'
mimetype = 'application/json'
o = Object.objects.filter(name__icontains="bin")
data = serializers.serialize(format, o)
return HttpResponse(data, mimetype)
I am only returning 1 Object with this query but it is of type QuerySet.
EDIT. Here is what data looks like when returned.
>>> o
[<Object: Bin Ber>]
>>> data = serializers.serialize(format, o)
>>> data
'[{"pk": 1, "model": "objects.object", "fields": {"name": "Bin Ber", "roof": 3, "depth": [3], "user": 1, "created_when": "2011-08-16 03:11:36", "shared": false, "projects": [1], "description": null}}]'
Based on your edits: