我将 Dajaxice 库与 django 一起使用。这些是我的 ajax.py 方法:
def get_by_date_queryset():
#return model.objects.latest('created_on')
return Article.objects.all().order_by('created_on')
def example1(request):
""" Handling sorting requests """
jsonList = []
queryset = get_by_date_queryset()
json_serializer = serializers.get_serializer("json")()
return json_serializer.serialize(queryset, ensure_ascii=False)
有HTML:
<script>
function my_js_callback(data){
alert(data) //this gives me [object Object],[object Object],[object Object]
alert(data[0]) //this gives [object Object]
alert(data[0].title) // fail
}
</script>
<button type="button" onclick="Dajaxice.content.example1(my_js_callback);">Click Me!</button>
而且我无法从对象中获取我的字段...请帮助