【发布时间】:2013-05-15 11:45:55
【问题描述】:
我正在尝试接收从我的 jquery post 调用发送的 json 对象,如下面的代码所示。当
simplejson.loads(request.POST)
被评论。但是,一旦我尝试对请求执行某些操作,我就会收到内部服务器错误 500。任何想法或任何其他方式来处理 json?
views.py
@csrf_exempt
def post_post(request):
print 'post_post'
if request.method == 'POST':
print 'POST'
messageData = simplejson.load(request.POST)
return HttpResponse(simplejson.dumps("POST OK!"))
else:
return HttpResponse(simplejson.dumps("POST NOT OK!"))
projectViewModel.js
var m = "Hello World";
console.log(m);
$.ajax({
url: 'postNewPost/',
type: 'POST',
dataType: 'json',
data: {client_response: JSON.stringify(m)},
success: function(result) {
console.log(result);
}
});
【问题讨论】:
-
你的日志说是什么问题?
-
在你的代码中你写的是
simplejson.load而不是simplejson.loads。是不是打错字了?
标签: jquery python ajax django post