Return a a json object from an ajax call to a django view -
am trying return json object render grid in template. how it.
views.py def ajax_up(request): history_data=upload_history.objects.all() history=serializers.serialize("json",history_data) return httpresponse( history, mimetype='application/json' ) html $(".reply").click(function(){ $.ajax({ url: "/ajax_up/", type: 'get', //this default though, don't need mention datatype: "json", success: function(data) { alert("awasome"+ data) }, failure: function(data) { alert('got error'); } });
so declare object hold data as
var data = {{history|safe}};
where history returned ajax call in view above when alert(data), [object object],[object object]..... can 1 please?
sounds it's working, alert
displays string. since data not string, it'll show [object object
].
either serialize data json.stringify
or use console.log
instead of alert
see data in browser javascript console.
Comments
Post a Comment