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<data.length;i++){
var ls = data[i];
html +="<option> "+ls.fields.name +"</option>";
}
$("#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)