Python Django框架通过ajax传递数据到前端并显示

 ajax代码如下:

$(document).ready(function() {
            $.ajax({
                url : "/stu/register_sql",
                dataType : "json",
                type : "get",
                async : true,
                success : function(data) { 
                var html = "";
                for(var i=0;i";
                    }
                    $("#grade").html(html);
                },
            })
        });

Django代码: 

from django.core import serializers
grade = Grade.objects.all()
ajax_testvalue = serializers.serialize("json", Grade.objects.all())
return HttpResponse(ajax_testvalue)

 

你可能感兴趣的:(python)