jqery 讀 python 的dictionary
請問各位
在後端將查詢結果存成python的 dictionary 並轉成 json格式
def ajax(request):
a = mymodels.objects.all()[0]
result = {}
result['name'] = a.name
result['age'] = a.age
result = simplejson.dumps(result)
return HttpResponse(result)
而在前端使用$.getJSON 讀取並呈現
$.getJSON("/rpc",function(json){
for(i=0;i<json.length;i++){
$(".containtest").append("<li>"+json[i].name+"<ul><li>"
+json[i].age+</li></ul></li>);
}
});
麻煩請告知問題所在? |