【发布时间】:2014-07-22 19:03:05
【问题描述】:
这是我的index.htmljavascript:
$('#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 发布到 url show.html,但现在我只能在控制台日志中看到 json。
【问题讨论】:
-
对于初学者,只需返回
request.body而不是OK
标签: javascript python json django