这是我的index.html
javascript:
$('#clickme').bind('click',function(){
var url = "/lms/quizes/show/";
var data = {"size": "width=8, height=9", "weight": "8 kg", "desc": "'&='"};
var string_data = JSON.stringify(data);
$.ajax({
type: "POST",
url: url,
async: true,
data: JSON.stringify(data),
success: function(response) {
alert(JSON.stringify(data));
}
});
})
这是我的views.py:
@csrf_exempt
def show(request):
if request.is_ajax():
if request.method == 'POST':
print 'Raw Data: "%s"' % request.body
return HttpResponse(request, content_type="application/json")
我想将json发布到网址show.html
,但是现在我只能在控制台日志中看到json。
答案 0 :(得分:0)
而不是
return HttpResponse("OK")
尝试
return HttpResponse(request, content_type="application/json")